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.
@shopify/react-idle
Advanced tools
@shopify/react-idle
Utilities for working with idle callbacks in React.
$ yarn add @shopify/react-idle
This library provides a hook (useIdleCallback
) and a component (OnIdle
) for registering a callback to run in the next idle callback.
Note: this callback is not called with any arguments, unlike direct usage of
requestIdleCallback
. This makes it more suited for use with discrete operations, rather than ones that will need to schedule themselves for subsequent idle callbacks if the work has not been completed.
import {useCallback} from 'react';
import {useIdleCallback, OnIdle} from '@shopify/react-idle';
function MyComponent() {
const callback = useCallback(() => {
console.log('Hello from an idle callback!');
}, []);
useIdleCallback(callback);
// or
return <OnIdle perform={callback} />;
}
If the callback ever changes, or the component unmounts, the original callback will not be run.
UnsupportedBehavior
Because not every browser supports idle callbacks, this library allows you to specify the behavior of perform
when requestIdleCallback
is not present. There are currently two options (each of which can be passed as an unsupportedBehavior
option for the hook, or an unsupportedBehavior
prop of the component):
UnsupportedBehavior.AnimationFrame
(default): run the callback in the next animation frame using requestAnimationFrame
.UnsupportedBehavior.Immediate
: run the callback immediately on mount.import {useIdleCallback, UnsupportedBehavior} from '@shopify/react-idle';
function MyComponent() {
useIdleCallback(doSomethingThatCanBeDeferred, {
unsupportedBehavior: UnsupportedBehavior.Immediate,
});
return null;
}
Because the typings for requestIdleCallback
are not yet provided by the TypeScript standard library, this module also exports a number of types that are needed to interact with these globals.
FAQs
Utilities for working with idle callbacks in React
The npm package @shopify/react-idle receives a total of 15,163 weekly downloads. As such, @shopify/react-idle popularity was classified as popular.
We found that @shopify/react-idle demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 24 open source maintainers 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.