React hook for api-poller-worker
npm install use-api-poller-worker  
> React hook for api-poller-worker
use-api-poller-worker is a React hook that you can use to integrate api-poller-worker into your React app.
- Installation
- Usage
- API
- Functions
- useApiPollerWorker
- Types
- Msg
###### ⇡ Top
``sh`
npm install use-api-poller-worker
###### ⇡ Top
This hook takes the same options as the ApiPollerWorker class from 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.
`ts
const MyComponent = () => {
const [items, setItems] = React.useState
const callback = React.useCallback<(data: Msg
setItems(data);
}, [setItems]);
useApiPollerWorker
workerUrl: '
}, callback);
return {
###### ⇡ Top
API
$3
####
useApiPollerWorkerThis is the default export.
`ts
import useApiPollerWorker from 'use-api-poller-worker';function useApiPollerWorker(
options: ApiPollerWorkerOptions,
callback: (data: Msg) => void,
)
`Both
ApiPollerWorkerOptions and Msg come from api-poller-worker. You might want to import Msg for type safety. This library re-exports Msg for convenience.useApiPollerWorker also accepts a generic, T for the type of resource you're polling.###### ⇡ Top
$3
####
MsgRepresents the contents of a message from the underlying polling library.
`ts
import { Msg } from 'use-api-poller-worker';
``ts
interface Msg {
newItems: Records;
updatedItems: Records;
removedItems: string[];
}
``###### ⇡ Top