
Product
Socket Now Supports pylock.toml Files
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
react-detectable-overflow
Advanced tools
A React hook and component detecting overflow state.
npm install react-detectable-overflow
or
yarn add react-detectable-overflow
import * as React from 'react';
import { useOverflowDetector } from 'react-detectable-overflow';
const SampleComponent = () => {
const { ref, overflow } = useOverflowDetector({});
return (
<div
ref={ref}
style={{
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
overflow: 'hidden',
width: '120px',
backgroundColor: overflow ? 'red' : 'green',
}}
>
This is a sample text.
</div>
);
};
import * as React from 'react';
import DetectableOverflow from 'react-detectable-overflow';
const SampleComponent = () => {
const [overflow, setOverflow] = useState(false);
return (
<DetectableOverflow
onChange={setOverflow}
style={{
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
overflow: 'hidden',
width: '120px',
backgroundColor: overflow ? '#F9E9CF' : '#BCF2E7',
}}
>
This is a sample text.
</DetectableOverflow>
);
};
Be careful when the size of children
content depends on overflow state. The following code perhaps causes the infinite loop of changing overflow
state.
import * as React from 'react';
import { useOverflowDetector } from 'react-detectable-overflow';
// DO NOT WRITE LIKE THIS!
const SampleComponent = () => {
const { ref, overflow } = useOverflowDetector({});
return <div ref={ref}>{overflow ? 'short' : 'loooooooooooooooooooooooooooooooooooooong'}</div>;
};
This package is released under the MIT License, see LICENSE
handleHeight
and handleWidth
FAQs
React hook/component to detect overflow state
The npm package react-detectable-overflow receives a total of 4,518 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.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Security News
Research
Socket uncovered two npm packages that register hidden HTTP endpoints to delete all files on command.
Research
Security News
Malicious Ruby gems typosquat Fastlane plugins to steal Telegram bot tokens, messages, and files, exploiting demand after Vietnam’s Telegram ban.