
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
@brianmcallister/use-api-poller-worker
Advanced tools
React hook for @brianmcallister/api-poller-worker
React hook for @brianmcallister/api-poller-worker
use-api-poller-worker
is a React hook that you can use to integrate @brianmcallister/api-poller-worker
into your React app.
npm install @brianmcallister/use-api-poller-worker
This hook takes the same options as the ApiPollerWorker
class from @brianmcallister/api-poller-worker
, plus an extra callback
argument which will be called when the underlying worker emits a message.
It's recommended to wrap your callback in React.useCallback
, so that your app does not unnecessarily re-render multiple times.
const MyComponent = () => {
const [items, setItems] = React.useState<Item>(null);
const callback = React.useCallback<(data: Msg<Item>) => void>(data => {
setItems(data);
}, [setItems]);
useApiPollerWorker<Item>({
workerUrl: '<my api endpoint>',
}, callback);
return {
<div>
{items}
</div>
};
};
useApiPollerWorker
This is the default export.
import useApiPollerWorker from '@brianmcallister/use-api-poller-worker';
function useApiPollerWorker<T extends {}>(
options: ApiPollerWorkerOptions,
callback: (data: Msg<T>) => void,
)
Both ApiPollerWorkerOptions
and Msg<T>
come from @brianmcallister/api-poller-worker
. You might want to import Msg<T>
for type safety. This library re-exports Msg<T>
for convenience.
useApiPollerWorker
also accepts a generic, T
for the type of resource you're polling.
Msg<T>
Represents the contents of a message from the underlying polling library.
import { Msg } from '@brianmcallister/use-api-poller-worker';
interface Msg<T> {
newItems: Records<T>;
updatedItems: Records<T>;
removedItems: string[];
}
FAQs
React hook for @brianmcallister/api-poller-worker
We found that @brianmcallister/use-api-poller-worker 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
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.