{"_id":"@bloodyaugust/use-fetch","_rev":"3-3c64cd79cb60f01a65ce9914ad45740e","name":"@bloodyaugust/use-fetch","dist-tags":{"latest":"1.1.1"},"versions":{"1.0.0":{"name":"@bloodyaugust/use-fetch","version":"1.0.0","description":"A simple, safe fetch custom hook for React.","main":"main.js","author":{"name":"Greyson Richey"},"license":"MIT","private":false,"repository":{"type":"git","url":"git+https://github.com/Bloodyaugust/use-fetch.git"},"keywords":["Hooks","Custom Hooks","Fetch","React"],"dependencies":{},"devDependencies":{"@babel/core":"^7.12.10","@babel/preset-env":"^7.12.11","@babel/preset-react":"^7.12.10","@rollup/plugin-babel":"^5.2.2","@rollup/plugin-commonjs":"^17.0.0","@testing-library/react-hooks":"^5.0.0","babel-jest":"^26.6.3","cross-fetch":"^3.0.6","jest":"^26.6.3","msw":"^0.25.0","react":"^17.0.1","react-dom":"^17.0.1","regenerator-runtime":"^0.13.7","rollup":"^2.36.1"},"scripts":{"test":"jest"},"gitHead":"ad8bbb6db708b16c10834b22d2b3c5fbba27b011","bugs":{"url":"https://github.com/Bloodyaugust/use-fetch/issues"},"homepage":"https://github.com/Bloodyaugust/use-fetch#readme","_id":"@bloodyaugust/use-fetch@1.0.0","_nodeVersion":"14.15.1","_npmVersion":"6.14.8","dist":{"integrity":"sha512-mLhr3bzMlPNjJHbF45AkIr5bJYvfklrqJ+P+sQ11fw4wsmBBDNtcTUlGPyV9VxFUx0e9RQgyxjZcBJqUHHH78g==","shasum":"23ab920db831eb81147b40619c897668209d6e75","tarball":"https://registry.npmjs.org/@bloodyaugust/use-fetch/-/use-fetch-1.0.0.tgz","fileCount":10,"unpackedSize":16468,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgAoBRCRA9TVsSAnZWagAAghUP/1ERtbSEqzYjTwuoSa9j\n/dTji6LJImbCZnNipCr7cc5awy8O7HMLc2gW6zp/1Ug9DRMtZwfNwTFOsNW9\nfdrHqea0P+NNCIjdJoIl2P0NYLPjSTZdCAqrw52J2K8DUCG6lxCz1+y3gGdm\nnw1VeNZWxWNeX8g6fhB38VnmnSy5aRCXkrFK8BK/8YtY8LOcD18f0MiqggMl\nedIrJGiwLkm99Je2tbVjIHH3MAD0DyjgFOFR3jjSPNJ5T29S5zpBe4iUjYcD\n2aqvGO8Ms0NVKTZilUfAs9G/c4DTHB/Mxj22rm6g+UaHeqWz0PeV33QQ2hPv\nHqQLCGTh5VnBOmkpEpb58R5iiAU4kQjXCHmcThl1WvYNcXYcYMruHA47LMCm\nBgaEzu3NR/akBY7hI2MxVZS9aF6Krj628qN/GvOQk2LNdDEUdRTuGMq6LQkj\n8il/CprBOeXz1dh/E2cmsqfMRdePdKhdID4Syqre5AVngZD3/t8coGIxy8Hh\nSWw72etX4g+Z21OVceRtn/R61dQg+jyOdOu8X3/MT0OMbuJ8nrDUPut3F71W\nKbdHkrhtGkFzHoeZf0ofFbZgMRy3Nz2qjj0WQ6htCfrPBBRmX++XygDj5XgW\n70fhMnMvMXDtnZ9qQtLl7KRRFrUJfNz7RteK5xn396tJ1FdrmupRyuMaXsUa\nt53B\r\n=80h4\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD8CKnixKkMLGrpY1WJuDmYbfRpZXSquwVC2F9JjGh22gIgSevFmBLu6UID4iHKZlyVeC2ynh8BfTPSr4RcupKavCk="}]},"_npmUser":{"name":"bloodyaugust","email":"greysonrichey@gmail.com"},"directories":{},"maintainers":[{"name":"bloodyaugust","email":"greysonrichey@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/use-fetch_1.0.0_1610776656909_0.5064580805825054"},"_hasShrinkwrap":false},"1.1.0":{"name":"@bloodyaugust/use-fetch","version":"1.1.0","description":"A simple, safe fetch custom hook for React.","main":"main.js","author":{"name":"Greyson Richey"},"license":"MIT","private":false,"repository":{"type":"git","url":"git+https://github.com/Bloodyaugust/use-fetch.git"},"keywords":["Hooks","Custom Hooks","Fetch","React"],"dependencies":{},"devDependencies":{"@babel/core":"^7.12.10","@babel/preset-env":"^7.12.11","@babel/preset-react":"^7.12.10","@rollup/plugin-babel":"^5.2.2","@rollup/plugin-commonjs":"^17.0.0","@testing-library/react-hooks":"^5.0.0","babel-jest":"^26.6.3","cross-fetch":"^3.0.6","jest":"^26.6.3","msw":"^0.25.0","react":"^17.0.1","react-dom":"^17.0.1","regenerator-runtime":"^0.13.7","rollup":"^2.36.1"},"scripts":{"test":"jest"},"_id":"@bloodyaugust/use-fetch@1.1.0","dist":{"shasum":"871ee73d2886b6e766b4fbf10c5b1fd4c6e257ac","integrity":"sha512-c+MY30rYOvR8sNUuD+Hw/qN/bf1vW0i0UatjHX+jrKyfjWwu05h4TQhDD0FW5sP/q5bFKcDfYAJgYDiUXVCG7Q==","tarball":"https://registry.npmjs.org/@bloodyaugust/use-fetch/-/use-fetch-1.1.0.tgz","fileCount":13,"unpackedSize":18218,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgW7VICRA9TVsSAnZWagAAyZsP/ArB5VpRoPN0KwslrxVO\nNciIRk7n2HZxz8vYnsOpmFSnGMW8IgVfDavze2FLIQoeWQyqWiZ3EAhZdVEO\nhqBL6jv3CrhveHZc7AmQ97gMCkfamxz3UmvmsZ4ot09xjn5RB6KjIdMMHcF6\njYLJ6ftmEEpPBcWP8iaXyTZlheXteRaOhWkftlSIUkcZpr9Flfvelh60arBk\njN6FkdXb2/9oqzzzQmfpoe579vRDki1MnPP67akTSg4/xrw7X3E12VirX4kE\n9pqj0XYusLmgDzQwA5L/ncaCrJIdgXqfGcKbyHzsSok6PW6zSulvJHp9NWKg\nIV9iOwX0md55H7nqfm3SCv6Um+HHcwHlEKlgdEUhTZXQegnpAzXQDMf1KEe+\nsXlIn/2NqC7byUPJbP+LNIhrraNcylAMntQ6XV490jJ0qYlaUiyydO8rYBLq\nZc9Eb8BfZs8Uc/G++jS/w3f42Umfm0vbkXiD7ZsKLfJ55PzyEkKT6YEaOTaW\nL9aXad3QnafoIFXsPlutDJv38EuNMQtuK8dCIJ3YORT8/1nltpxO1s2Rd0WH\nYau10AnT84DRWj5aOCbGSJZvc5rKiItuV5Kr15iNcFuDMqGB63nIOESvPuXw\nBTPXMHwiQPAdjQ2JUbaZPUsoojIPR+Y/yvLZlAp1QfXFWAyIbbzp6GSy6mML\nlIOJ\r\n=Ui2B\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFkzdUwtcipdbzsX49f3qWhz0XLvYaLp6D5e4ItsAgtiAiEA8hLm27rYFSsVuiv2cEVwHJhsvt/DbhVrW9gAxfVpjjc="}]},"_npmUser":{"name":"bloodyaugust","email":"greysonrichey@gmail.com"},"directories":{},"maintainers":[{"name":"bloodyaugust","email":"greysonrichey@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/use-fetch_1.1.0_1616622919772_0.28708562685084327"},"_hasShrinkwrap":false},"1.1.1":{"name":"@bloodyaugust/use-fetch","version":"1.1.1","description":"A simple, safe fetch custom hook for React.","main":"main.js","author":{"name":"Greyson Richey"},"license":"MIT","private":false,"repository":{"type":"git","url":"git+https://github.com/Bloodyaugust/use-fetch.git"},"keywords":["Hooks","Custom Hooks","Fetch","React"],"dependencies":{},"devDependencies":{"@babel/core":"^7.12.10","@babel/preset-env":"^7.12.11","@babel/preset-react":"^7.12.10","@rollup/plugin-babel":"^5.2.2","@rollup/plugin-commonjs":"^17.0.0","@testing-library/react-hooks":"^5.0.0","babel-jest":"^26.6.3","cross-fetch":"^3.0.6","jest":"^26.6.3","msw":"^0.25.0","react":"^17.0.1","react-dom":"^17.0.1","regenerator-runtime":"^0.13.7","rollup":"^2.36.1"},"scripts":{"test":"jest --detectOpenHandles"},"gitHead":"0aa0b66913c9913f7895cd3b80f486529fad63ae","bugs":{"url":"https://github.com/Bloodyaugust/use-fetch/issues"},"homepage":"https://github.com/Bloodyaugust/use-fetch#readme","_id":"@bloodyaugust/use-fetch@1.1.1","_nodeVersion":"16.17.0","_npmVersion":"8.15.0","dist":{"integrity":"sha512-ddpgv5gGZqlNjBDLPbaq+gRGsI4CpakgGwvsOXV12JQol7gyMqos0d60aUpn1ik2SF97kfw7odZ+ZGM1r15l8A==","shasum":"f41366743508e974a47f0fee0492ba1212723b64","tarball":"https://registry.npmjs.org/@bloodyaugust/use-fetch/-/use-fetch-1.1.1.tgz","fileCount":11,"unpackedSize":18735,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDEwvV+5MW9fgXKiaLN2TK+CPJlkJqQm/BZUed6mECb2AIgNOH7tWCtPgKTFukzQFSsm9pP7Jx027I9nBn3KdwN26g="}]},"_npmUser":{"name":"bloodyaugust","email":"greysonrichey@gmail.com"},"directories":{},"maintainers":[{"name":"bloodyaugust","email":"greysonrichey@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/use-fetch_1.1.1_1693427229750_0.08455720841879066"},"_hasShrinkwrap":false}},"time":{"created":"2021-01-16T05:57:36.872Z","1.0.0":"2021-01-16T05:57:37.058Z","modified":"2023-08-30T20:27:10.103Z","1.1.0":"2021-03-24T21:55:19.915Z","1.1.1":"2023-08-30T20:27:09.927Z"},"maintainers":[{"name":"bloodyaugust","email":"greysonrichey@gmail.com"}],"description":"A simple, safe fetch custom hook for React.","keywords":["Hooks","Custom Hooks","Fetch","React"],"repository":{"type":"git","url":"git+https://github.com/Bloodyaugust/use-fetch.git"},"author":{"name":"Greyson Richey"},"license":"MIT","readme":"# @bloodyaugust/use-fetch\n\nA simple, _safe_ fetch custom hook for React. Why safe? There's a good chance you've seen this before:\n\n```\nWarning: Can’t perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.\n```\n\nThis hook helps you avoid mutating state on components that are `unmounted` by providing you with the `mounted` state of the hook, and aborts in-flight requests on `unmount`.\n\n## Features\n\n- _Safe_: gives you the tools to avoid mutating state on `unmounted` components.\n- Simple: Just a hook! No `Context`s were harmed (or used) in the source of this library.\n- Flexible: you get the `response`, the `json`, and of course the `mounted` state.\n- Configurable: turn off automatic `json` parsing for those one-off cases.\n- Provides a convenient `Promise`-based API.\n- Aborts in-flight requests automatically if `unmounted`.\n- Rejects `Promise` if the `response` indicates failure.\n- No dependencies aside from `React`.\n\n## Install\n\n```bash\nnpm install @bloodyaugust/use-fetch\n# or, if using yarn\nyarn add @bloodyaugust/use-fetch\n```\n\n## Usage\n\nThis example demonstrates how you might get some todos with `useFetch` while being sure you don't mutate state after your component is `unmounted`.\n\n```jsx\nimport React, { useEffect, useState } from \"react\";\nimport useFetch from \"@bloodyaugust/use-fetch\";\n\nfunction TodoList() {\n  const { execute } = useFetch();\n  const [todos, setTodos] = useState([]);\n\n  useEffect(() => {\n    const getTodos = async () => {\n      await execute(\"https://jsonplaceholder.typicode.com/todos/\").then(\n        ({ json, mounted }) => {\n          if (mounted) {\n            setTodos(json);\n          }\n        }\n      );\n    };\n\n    getTodos();\n  }, []);\n\n  return (\n    <div>\n      {todos.map((todo) => {\n        <span key={todo.id}>{todo.title}</span>;\n      })}\n    </div>\n  );\n}\n```\n\n## API\n\n### Props\n\n```jsx\nuseFetch({\n  noJSON: bool, // Set true if you want to skip JSON parsing (no json key will be provided to the promise chain)\n});\n```\n\n### Execute\n\n`execute` is the function returned for invoking your fetch. It provides as consistent an API as it can, but there are some slight differences depending on if the request is successful, aborted, or failed for some other reason.\n\nParameters are the same as [fetch](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch).\n\n#### success\n\n```jsx\nuseFetch('https://jsonplaceholder.typicode.com/todos/')\n  .then({\n    response, // The fetch Response object\n    json, // The result of response.json() (not present if the noJSON prop was set)\n    mounted // The mounted state of the hook\n  } => {})\n```\n\n#### error with fetch (includes abort)\n\n```jsx\nuseFetch('https://jsonplaceholder.typicode.com/todos/')\n  .catch({\n    error // The Error object thrown by fetch\n  } => {})\n```\n\n#### response indicates failure (!response.ok)\n\n```jsx\nuseFetch('https://jsonplaceholder.typicode.com/todos/')\n  .catch({\n    response,\n    error, // new Error(`Request failed: ${response.status}`)\n    mounted\n  } => {})\n```\n\n### Completed\n\n`completed` is a ref returned from the hook to allow for determining the completion state of the fetch. It starts as `false`, but becomes true when the request completes for any reason (including abort).\n","readmeFilename":"README.md","homepage":"https://github.com/Bloodyaugust/use-fetch#readme","bugs":{"url":"https://github.com/Bloodyaugust/use-fetch/issues"}}