Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
react-page-visibility
Advanced tools
Declarative, nested, stateful, isomorphic page visibility for React
Declarative, nested, stateful, isomorphic page visibility for React
Are you polling your Backend on an interval basis? Are you running animations? What do you do if your tab is no longer visible?
See more classic use-cases in MDN Page Visibility API.
Well now you can react (Pun intended) to your app being in the background and invisible by conserving bandwidth and GPU calculations with ease. Introduction React Page Visibility:
Because React is cool. 'Nuff said.
But really, why not use a helper function?
Because you will then need to addEventListener
and removeEventListener
in your component lifecycle and that gets tedious.
Also, every time you use it you will need to check if your user's browser supports it and that gets tedious too.
Instead with react-page-visibility
everything is taken care of for you.
$ npm install --save react-page-visibility
A rotating carousel component that will be passed down a prop of whether to rotate the images or not based on whether page is visible.
usePageVisibility
hookimport React from 'react';
import { usePageVisibility } from 'react-page-visibility';
const AppContainer = () => {
const isVisible = usePageVisibility()
return <RotatingCarousel rotate={isVisible} />
}
onChange
callbackimport React from 'react';
import PageVisibility from 'react-page-visibility';
class AppContainer extends React.Component {
state = {
rotate: true
};
handleVisibilityChange = isVisible => {
this.setState({ rotate: !isVisible });
}
render() {
return (
<PageVisibility onChange={this.handleVisibilityChange}>
<RotatingCarousel rotate={this.state.rotate} />
</PageVisibility>
);
}
}
children
as function callbackimport React from 'react';
import PageVisibility from 'react-page-visibility';
const AppContainer = () => {
return (
<PageVisibility>
{ isVisible => <RotatingCarousel rotate={isVisible} /> }
</PageVisibility>
);
}
react-page-visibility
is an higher order component, you can pass to it an onChange
function:
onChange(handler)
Where handler
is the callback to run when the visibilityState
of the document changes:
Function handler(<Boolean> isVisible, <String> visibilityState)
isVisible
is a Boolean indicating whether document is considered visible to the user or not.visibilityState
is a String and can be one of visible
, hidden
, prerender
, unloaded
(if your browser supports those)Notice: previous versions had different arguments in the handler
Or you can use function as children pattern,
where children
is the callback to run when the visibilityState
of the document changes.
Function children(<Boolean> isVisible, <String> visibilityState)
See MDN Page Visibility API Properties overview
MIT © Gilad Peleg
FAQs
Declarative, nested, stateful, isomorphic page visibility for React
The npm package react-page-visibility receives a total of 48,611 weekly downloads. As such, react-page-visibility popularity was classified as popular.
We found that react-page-visibility 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.