
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-on-screen-extended
Advanced tools
A wrapper component to track if your react component is visible on screen
😎 Check if your react component are visible on the screen without pain and with performance in mind 😎!

View the demo.
$ npm install --save react-on-screen
$ yarn add react-on-screen
A UMD build is also available :
<script src="./dist/ReactOnScreen.min.js"></script>
import React from 'react';
import TrackVisibility from 'react-on-screen';
const ComponentToTrack = ({ isVisible }) => {
const style = {
background: isVisible ? 'red' : 'blue'
};
return <div style={style}>Hello</div>;
}
const YourApp = () => {
return (
{/* Some Stuff */}
<TrackVisibility>
<ComponentToTrack />
</TrackVisibility>
{/* Some Stuff */}
);
}
You can use a render props is you want to !
const YourApp = () => {
return (
<TrackVisibility>
{({ isVisible }) => isVisible && <ComponentToTrack />}
</TrackVisibility>
);
}
For many cases you may want to track the visibility only once. This can be done simply as follow :
const YourApp = () => {
return (
<TrackVisibility once>
<ComponentToTrack />
</TrackVisibility>
);
}
Using offset props can be usefull if you want to lazy load an image for instance.
const YourApp = () => {
return (
<TrackVisibility offset={1000}>
{({ isVisible }) => isVisible ? <ComponentToTrack /> : <Loading />}
</TrackVisibility>
);
}
You may want to consider that a component is visible as soon as a part of the component is visible on screen. You can use the partialVisibility props for that.
const YourApp = () => {
return (
<TrackVisibility partialVisibility>
{({ isVisible }) => <ComponentToTrack />}
</TrackVisibility>
);
}
| props | type | default | description |
|---|---|---|---|
| once | bool | false | If set to true track the visibility only once and remove the event listeners |
| throttleInterval | int | 150 | Tweak the event listeners. See David Corbacho's article |
| children | React Components | - | Can be on or many react components |
| style | object | - | Style attributes |
| className | string | - | Css classes |
| offset | number | 0 | Allows you to specify how far left or above of the viewport you want to set isVisible to true |
| partialVisibility | bool | false | Set isVisible to true on element as soon as any part is in the viewport |
Any contributions is welcome !
$ npm run lint$ npm run test$ npm run build // will lint and run test beforeisComponentVisible call into next tickLicensed under MIT
FAQs
A wrapper component to track if your react component is visible on screen
We found that react-on-screen-extended 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.