
Security News
pnpm 10.12 Introduces Global Virtual Store and Expanded Version Catalogs
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.
react-detectable-overflow
Advanced tools
A React component that informs when the overflowed status is changed.
A React component which is able to detect changes in the state that the contents is overflowed.
npm install react-detectable-overflow
or
yarn add react-detectable-overflow
prop | required | type | description | default |
---|---|---|---|---|
tag | string | element type (e.g. 'p' , 'div' ) | 'div' | |
style | object | css style of the element | { width: '100%', textOverflow: 'ellipsis', whiteSpace: 'nowrap', overflow: 'hidden', } | |
className | string | class names | '' | |
onChange | (isOverflowed: boolean) => void | callback function called when its overflowing status is changed |
import * as React from 'react';
import DetectableOverflow from 'react-detectable-overflow';
class SampleComponent extends React.Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
}
handleChange(isOverflowed) {
// do something
}
render {
return (
<DetectableOverflow onChange={this.handleChange}>
This is a sample text.
</DetectableOverflow>
);
}
}
Be careful when you change the length of children
contents by onChange callback. The following code perhaps causes the infinite loop of changing isOverflowed
state.
// DO NOT WRITE LIKE THIS!
<DetectableOverflow
onChange={(isOverflowed) => {
if (isOverflowed) {
this.setState({ value: 'short' });
} else {
this.setState({ value: 'loooooooooooooooooooooooooooooooooooooong' });
}
}}
>
{this.state.value}
</DetectableOverflow>
This package is released under the MIT License, see LICENSE
FAQs
React hook/component to detect overflow state
The npm package react-detectable-overflow receives a total of 4,420 weekly downloads. As such, react-detectable-overflow popularity was classified as popular.
We found that react-detectable-overflow demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.
Security News
Amaro 1.0 lays the groundwork for stable TypeScript support in Node.js, bringing official .ts loading closer to reality.
Research
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.