{"_id":"@brianmcallister/use-api-poller-worker","_rev":"2-39fb381c852b8809e73a900318ec0076","name":"@brianmcallister/use-api-poller-worker","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@brianmcallister/use-api-poller-worker","version":"0.0.1","description":"React hook for @brianmcallister/api-poller-worker","main":"dist/useApiPollerWorker.js","repository":{"type":"git","url":"git+https://github.com/brianmcallister/use-api-poller-worker.git"},"license":"MIT","author":{"name":"Brian Wm. McAllister","email":"brian@brianmcallister.com","url":"https://www.brianmcallister.com"},"keywords":["react","hook","api","polling","real-time","webworker","javascript"],"scripts":{"lint":"eslint --cache --ext .js,.jsx,.ts,.tsx --ignore-path .gitignore ./src","prepare":"rimraf dist && tsc && rimraf dist/*/__tests__","stylelint":"stylelint demo/**/*.scss","test":"jest --coverage","types":"tsc --noEmit"},"dependencies":{"@brianmcallister/api-poller-worker":"^1.1.0","@types/react":"^16.9.11"},"optionalDependencies":{"@types/react":"^16.9.11"},"peerDependencies":{"react":"^16.8"},"devDependencies":{"@testing-library/react-hooks":"3.2.1","@types/jest":"24.0.23","@typescript-eslint/eslint-plugin":"2.7.0","eslint":"6.6.0","eslint-config-airbnb":"18.0.1","eslint-config-airbnb-typescript":"6.1.0","eslint-config-prettier":"6.5.0","eslint-plugin-eslint-comments":"3.1.2","eslint-plugin-import":"2.18.2","eslint-plugin-jest":"23.0.3","eslint-plugin-jsx-a11y":"6.2.3","eslint-plugin-prettier":"3.1.1","eslint-plugin-promise":"4.2.1","eslint-plugin-react":"7.16.0","eslint-plugin-react-hooks":"2.2.0","eslint-plugin-unicorn":"12.1.0","jest":"24.9.0","prettier":"1.19.1","react":"^16.12.0","react-test-renderer":"16.12.0","rimraf":"3.0.0","stylelint":"11.1.1","stylelint-config-recommended":"3.0.0","stylelint-config-sass-guidelines":"6.1.0","stylelint-scss":"3.12.1","ts-jest":"24.1.0","typescript":"3.7.2"},"gitHead":"849bfd5a8498f80221412951a8b9b59772044ee5","bugs":{"url":"https://github.com/brianmcallister/use-api-poller-worker/issues"},"homepage":"https://github.com/brianmcallister/use-api-poller-worker#readme","_id":"@brianmcallister/use-api-poller-worker@0.0.1","_npmVersion":"6.4.1","_nodeVersion":"10.15.2","_npmUser":{"name":"brianmcallister","email":"brian@brianmcallister.com"},"dist":{"integrity":"sha512-S03WW7QGoxIpb1KgPjnP9g24JX8PrQbVunRkDUPuElh2UXKVsNvg99mTt5aCiieg6BaHOWOKpitAz68oTpbE0Q==","shasum":"b22b515bb8c371becd0370b87b5c8d9712b946db","tarball":"https://registry.npmjs.org/@brianmcallister/use-api-poller-worker/-/use-api-poller-worker-0.0.1.tgz","fileCount":5,"unpackedSize":7769,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJd1MAdCRA9TVsSAnZWagAA4KsP/RnGrreK6+iXQJwuj51D\nkRiXPW1+HDUQAH5pdVAAPNUELdd/fB/g/lUtE8reo2E45S5qkJ+w3yFt+ts1\nVaE1Sjio/AlC/18fUskbWfFqB2263ZxWQjI5kQZzdKIJ3D71rV1bN1A8Wqjv\nMeDNkHkaFXfCzW9UpP2VRonarCgaghwhN+h4l16OwHrhSSCpyEmFKVXtJBtL\nWAeSGcq2B9BPB+6THSyNkdUqScOPj4+PDI9rWFJPs98Fn0NKeLpt6mH8Y+T9\n5347SFidgg2Zdg9sajNts5i3mx2BJvgYS6hM3F4XnuVr0T1d1zb/jPWOuf8o\n4tiEo/IXNu/cdBbjR7eXowXX6TnVVCFJ8uPPu64z0XWsQ7d1P41Y/n5XoS6N\nK6681wqNGib/RywuVxj1r2Yo46dno9Eh0AhSiNUqUaeX0CdKltbQtTdk+Nt4\nJn6UNB6XcfPptRYyL9C+k6yiYlMesBgKPxY4yIA7KxHX/vI65O9NgyVZcsBD\nPVV3jCWAx3tBBXDEVoOE8hto8Anxo8zKnTEvNgUfuGyZH5eZ73k6oR88ICEr\nSDmpjyV1yTgAp+WO3dQ5zSZjqfkpIM12WXfs6vUJt05tGKBL9DeF65Rj+U36\nAt1OkRgG0QSl8gijqSlajIPpp258tBvUGa3g109x2tWVk1nGGzCDvfeD/nhn\n8oE7\r\n=QkOa\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCyRX3zSaWvHBi4JHOoqlRKdTc3lI1eyu6iuA8HDVTJewIhALtkWVIf2SlLUAhUppxbCztPX7Wt0xHmWD2m+vR8PBzO"}]},"maintainers":[{"name":"brianmcallister","email":"brian@brianmcallister.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/use-api-poller-worker_0.0.1_1574223901281_0.923616030754913"},"_hasShrinkwrap":false,"deprecated":"Packaged moved to use-api-poller-worker"}},"time":{"created":"2019-11-20T04:25:01.280Z","0.0.1":"2019-11-20T04:25:01.395Z","modified":"2022-04-04T20:32:02.509Z"},"maintainers":[{"name":"brianmcallister","email":"brian@brianmcallister.com"}],"description":"React hook for @brianmcallister/api-poller-worker","homepage":"https://github.com/brianmcallister/use-api-poller-worker#readme","keywords":["react","hook","api","polling","real-time","webworker","javascript"],"repository":{"type":"git","url":"git+https://github.com/brianmcallister/use-api-poller-worker.git"},"author":{"name":"Brian Wm. McAllister","email":"brian@brianmcallister.com","url":"https://www.brianmcallister.com"},"bugs":{"url":"https://github.com/brianmcallister/use-api-poller-worker/issues"},"license":"MIT","readme":"# @brianmcallister/use-api-poller-worker\n\n[![codecov](https://codecov.io/gh/brianmcallister/use-api-poller-worker/branch/master/graph/badge.svg)](https://codecov.io/gh/brianmcallister/use-api-poller-worker) [![CircleCI](https://circleci.com/gh/brianmcallister/use-api-poller-worker.svg?style=svg)](https://circleci.com/gh/brianmcallister/use-api-poller-worker) [![npm version](https://img.shields.io/npm/v/@brianmcallister/use-api-poller-worker?label=version&color=%2354C536&logo=npm)](https://www.npmjs.com/package/@brianmcallister/use-api-poller-worker)\n\n> React hook for @brianmcallister/api-poller-worker\n\n`use-api-poller-worker` is a React hook that you can use to integrate [`@brianmcallister/api-poller-worker`](https://github.com/brianmcallister/api-poller-worker) into your React app.\n\n## Table of contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [API](#api)\n  - Functions\n    - [`useApiPollerWorker`](#useapipollerworker)\n  - Types\n    - [`Msg<T>`](#msgt)\n\n###### [⇡ Top](#table-of-contents)\n\n## Installation\n\n```sh\nnpm install @brianmcallister/use-api-poller-worker\n```\n\n###### [⇡ Top](#table-of-contents)\n\n## Usage\n\nThis hook takes the same options as the `ApiPollerWorker` class from [`@brianmcallister/api-poller-worker`](https://github.com/brianmcallister/api-poller-worker), plus an extra `callback` argument which will be called when the underlying worker emits a message.\n\nIt's recommended to wrap your callback in `React.useCallback`, so that your app does not unnecessarily re-render multiple times.\n\n```ts\nconst MyComponent = () => {\n  const [items, setItems] = React.useState<Item>(null);\n  const callback = React.useCallback<(data: Msg<Item>) => void>(data => {\n    setItems(data);\n  }, [setItems]);\n\n  useApiPollerWorker<Item>({\n    workerUrl: '<my api endpoint>',\n  }, callback);\n\n  return {\n    <div>\n      {items}\n    </div>\n  };\n};\n```\n\n###### [⇡ Top](#table-of-contents)\n\n## API\n\n### Functions\n\n#### `useApiPollerWorker`\n\nThis is the default export.\n\n```ts\nimport useApiPollerWorker from '@brianmcallister/use-api-poller-worker';\n\nfunction useApiPollerWorker<T extends {}>(\n  options: ApiPollerWorkerOptions,\n  callback: (data: Msg<T>) => void,\n)\n```\n\nBoth `ApiPollerWorkerOptions` and `Msg<T>` come from [`@brianmcallister/api-poller-worker`](https://github.com/brianmcallister/api-poller-worker). You might want to import `Msg<T>` for type safety. This library re-exports `Msg<T>` for convenience.\n\n`useApiPollerWorker` also accepts a generic, `T` for the type of resource you're polling.\n\n###### [⇡ Top](#table-of-contents)\n\n### Types\n\n#### `Msg<T>`\n\nRepresents the contents of a message from the underlying polling library.\n\n```ts\nimport { Msg } from '@brianmcallister/use-api-poller-worker';\n```\n\n```ts\ninterface Msg<T> {\n  newItems: Records<T>;\n  updatedItems: Records<T>;\n  removedItems: string[];\n}\n```\n\n###### [⇡ Top](#table-of-contents)\n","readmeFilename":"README.md"}