{"_id":"@chengsokdara/react-hooks-async","_rev":"1-179ec48c75c654ea3beb5bb305429b6a","name":"@chengsokdara/react-hooks-async","dist-tags":{"latest":"0.0.2"},"versions":{"0.0.1":{"name":"@chengsokdara/react-hooks-async","version":"0.0.1","description":"Asynchronous React Hooks","keywords":["react","hook","hooks","async","promise","await","asynchronous","use","useEffect","useCallback"],"homepage":"https://github.com/chengsokdara/react-hooks-async#readme","bugs":{"url":"https://github.com/chengsokdara/react-hooks-async/issues"},"license":"MIT","author":{"name":"Sokdara Cheng"},"repository":{"type":"git","url":"https://github.com/github:chengsokdara/react-hooks-async"},"scripts":{"ts-types":"tsc","build-dev":"rimraf lib && env NODE_ENV=development tsup","build-prod":"rimraf dist && env NODE_ENV=production tsup","build-watch":"rimraf lib && env NODE_ENV=development tsup --watch","lint-fix":"eslint ./src --ext .ts,.tsx --quiet --fix --ignore-path ./.gitignore","lint-format":"prettier  --loglevel warn --write \"./**/*.{ts,tsx,css,md,json}\" ","lint":"yarn lint-format && yarn lint-fix ","test":"yarn run tsc && yarn run lint","prepublishOnly":"yarn run build-prod"},"devDependencies":{"@types/node":"^18.14.6","@types/react":"^18.0.28","@typescript-eslint/eslint-plugin":"^5.54.1","@typescript-eslint/parser":"^5.54.1","eslint":"^8.35.0","eslint-config-prettier":"^8.7.0","eslint-plugin-prettier":"^4.2.1","prettier":"^2.8.4","react":"^18.2.0","tsup":"^6.6.3","typescript":"^4.9.5"},"peerDependencies":{"react":"*"},"main":"dist/index.cjs","module":"dist/index.js","types":"dist/index.d.ts","exports":{"node":"./dist/index.cjs","require":"./dist/index.cjs","import":"./dist/index.js","default":"./dist/index.cjs"},"type":"module","publishConfig":{"access":"public"},"licenseText":"MIT License\n\nCopyright (c) 2023 Sokdara Cheng\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","_id":"@chengsokdara/react-hooks-async@0.0.1","dist":{"shasum":"627b33d738b6dcf7a072de4d4d8a0f5001ff1475","integrity":"sha512-4D7xTTAgOgQHVo4iKG4nGZbXkTIQJLgf1jvK5P2HMxGyopQsWdDNqKCU5dbo+od4La7tV66Z8C5uZ5Fm7/c14Q==","tarball":"https://registry.npmjs.org/@chengsokdara/react-hooks-async/-/react-hooks-async-0.0.1.tgz","fileCount":21,"unpackedSize":7787,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC6Q2oORP9WXrD8VdPIqwFpdtFoOc0ADc+QSzlLD7y/pQIgOKGKsmf7AK3g217LXjziSzoTVQQ6HMiDRdeRrzeL+Qc="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkCBZoACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpU5BAAjdKuGyu7x6rCplDOA6/d0zBGVhgVMG0E7D4qXoIkXJ30gtTp\r\nYrXzS63DcgeLy+memjKYtBheneKsH+6eAR9RXqffBHhSCCS7XHzWIKpwAmIo\r\n2tZeKE/J7iFpHBo6/ocm7kCXbS6OgbRFp0q9FyLdxi+owzFmjP3JsLnoq68T\r\neiAPvITp4zDOXZSWM418wPuruNL8trGRXIPvI2JXsV7nN+lpSYvs1w94d1wL\r\nJ4Qf7tSYicwyXab0laDKL7jFSbFbxlwd2+9PwLk2hjrfrIeCakA7S0YJy7hr\r\n2fY59fzwtn4a+5NkdCHh86JRDwlu0Dyl/oGy2tIVPBojLARI4Ohk4AUBMSeP\r\ny2hfkiH8BfkVnHf/DfFOtQfr6QdCXdbSbXlssEv+Qh6NKY12yM3sdYgMtObI\r\nHD/YLvIrMwOTzAn+FhzjsBMmxIQHoG/o5iNkDVwujTTDP1KwL7tgA93uS4Lu\r\nvfAMvVFj7Ki4/L1s8bhnyCST3HhX0bwXolDyPeeib2WFmi1FDtbJpom0Akyq\r\n5I6Vno07Wyj9E9uL5z3ZUfCHdJ6s8p8YcyAKzaJ8dHoMGJKMG7KKHKEA7apE\r\nvl7Y3jtIQOY5H/q+Ezks3q1Jebwb4iGgBuz8++A5v81m19QpAs5ALs5HBRWj\r\nCDV6I8Ch0AL7vu+SxgWBeIcNY3++bVdYNiY=\r\n=6LHi\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"chengsokdara","email":"chengsokdara@gmail.com"},"directories":{},"maintainers":[{"name":"chengsokdara","email":"chengsokdara@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/react-hooks-async_0.0.1_1678251624191_0.28283935370075897"},"_hasShrinkwrap":false},"0.0.2":{"name":"@chengsokdara/react-hooks-async","version":"0.0.2","description":"Asynchronous React Hooks","keywords":["react","hook","hooks","async","promise","await","asynchronous","use","useEffect","useCallback"],"homepage":"https://github.com/chengsokdara/react-hooks-async#readme","bugs":{"url":"https://github.com/chengsokdara/react-hooks-async/issues"},"license":"MIT","author":{"name":"Sokdara Cheng"},"repository":{"type":"git","url":"https://github.com/github:chengsokdara/react-hooks-async"},"scripts":{"ts-types":"tsc","build-dev":"rimraf lib && env NODE_ENV=development tsup","build-prod":"rimraf dist && env NODE_ENV=production tsup","build-watch":"rimraf lib && env NODE_ENV=development tsup --watch","lint-fix":"eslint ./src --ext .ts,.tsx --quiet --fix --ignore-path ./.gitignore","lint-format":"prettier  --loglevel warn --write \"./**/*.{ts,tsx,css,md,json}\" ","lint":"yarn lint-format && yarn lint-fix ","test":"yarn run tsc && yarn run lint","prepublishOnly":"yarn run build-prod"},"devDependencies":{"@types/node":"^18.14.6","@types/react":"^18.0.28","@typescript-eslint/eslint-plugin":"^5.54.1","@typescript-eslint/parser":"^5.54.1","eslint":"^8.35.0","eslint-config-prettier":"^8.7.0","eslint-plugin-prettier":"^4.2.1","prettier":"^2.8.4","react":"^18.2.0","tsup":"^6.6.3","typescript":"^4.9.5"},"peerDependencies":{"react":"*"},"main":"dist/index.cjs","module":"dist/index.js","types":"dist/index.d.ts","exports":{"node":"./dist/index.cjs","require":"./dist/index.cjs","import":"./dist/index.js","default":"./dist/index.cjs"},"type":"module","publishConfig":{"access":"public"},"licenseText":"MIT License\n\nCopyright (c) 2023 Sokdara Cheng\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","_id":"@chengsokdara/react-hooks-async@0.0.2","dist":{"shasum":"06adba2c042b606bbaf16cfde97ebbceee3584b6","integrity":"sha512-m7fyEj3b4qLADHHrAkucVBBpuJJ+ZjrQjTSyj/TmQTZrmgDS5MDEoYLaN48+YSho1z8YxelUwDTgUEdSjR03fw==","tarball":"https://registry.npmjs.org/@chengsokdara/react-hooks-async/-/react-hooks-async-0.0.2.tgz","fileCount":27,"unpackedSize":10422,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDxRFtzQHjTPQl7ZA5QEHgPnVlQt/5GdiO+tFftxBkOGgIhAMu2RX87W5IMfsF2G7R68mfI+Wwks3wOYQu88XuTxNDu"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkCaK4ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp1FRAAgtCdxqnuulLELpvxBPF9H2Oi5SfDuPIu3hMpN3mneShOJK05\r\nbzHnnehIBgyOkUtznNKWUVU/oIOzWD/dXpiyzjv9DNmieNXJ5mnU/E018AV0\r\nnag/E9XUO87NYb1p0HbcdjoBBfZAkoPbJHZjNxgKRyr4P6bK2Hfq87ZrXKFm\r\nsNlrFyqTN6R8qaYb0gG4afMb0Gb7fyrZJm55XhhDBW53saT7EcGTQxqy5fIY\r\n2xfm42ozlyrWrdpUE/zOw/jZzey6KgpEbVS2hAy9sV4r66NNwFMFp2qu75XL\r\nlD6OGS7/8Q53WEiggQegtq4OFphon3RWRg4EROoxJ9GHrDklCRiHZ2RALUk2\r\n4WYrN8IA6/7n9VYK897l7YzaU6fVm4RBYMCfbLlt2bTkii501vzAfV4aUr7Q\r\neq5sRRRXFN3B6f27w8q2M4imltRFcWI9HcRdkAPWtgp/kvI3rt4VGmHCAyia\r\n4R0T6ISfXKKxYvenTqpgy3+qhqKf3otYDFV81M5l8EkOn2XEhgWnpuVK2MHo\r\nbq9N6Wy+5hNZF7ogEXIRBz3bGsYPRpJ2oveGbb2pEHUVvbhR11CS5NfuCSJi\r\nf/f2SMc7EXfKR0CrDz2gVHICtzsZP4nfqdqaRjbEmEij7iUeiiTCRTGeZz1f\r\nPHgCW6V2yvSlnaBkQpsw8i5R7c4aiEwtVUM=\r\n=qrW6\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"chengsokdara","email":"chengsokdara@gmail.com"},"directories":{},"maintainers":[{"name":"chengsokdara","email":"chengsokdara@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/react-hooks-async_0.0.2_1678353079861_0.6457207462464771"},"_hasShrinkwrap":false}},"time":{"created":"2023-03-08T05:00:24.077Z","0.0.1":"2023-03-08T05:00:24.382Z","modified":"2023-03-09T09:11:20.121Z","0.0.2":"2023-03-09T09:11:20.042Z"},"maintainers":[{"name":"chengsokdara","email":"chengsokdara@gmail.com"}],"description":"Asynchronous React Hooks","homepage":"https://github.com/chengsokdara/react-hooks-async#readme","keywords":["react","hook","hooks","async","promise","await","asynchronous","use","useEffect","useCallback"],"repository":{"type":"git","url":"https://github.com/github:chengsokdara/react-hooks-async"},"author":{"name":"Sokdara Cheng"},"bugs":{"url":"https://github.com/chengsokdara/react-hooks-async/issues"},"license":"MIT","readme":"# Asynchronous React Hooks\n\nWrite React hooks in asynchronous way\n\n---\n\n_Try out useWhisper a React hook for OpenAI Whisper API_\n\n[https://github.com/chengsokdara/use-whisper](https://github.com/chengsokdara/use-whisper)\n\n- ### Install\n\n`npm i @chengsokdara/react-hooks-async`\n\n`yarn add @chengsokdara/react-hooks-async`\n\n- ### Usage\n\n- ###### useCallbackAsync\n\n```typescript\nimport { useCallbackAsync } from '@chengsokdara/react-hooks-async'\n\nconst App = () => {\n  const sampleCallback = useCallbackAsync(\n    // will be wrapped in try catch\n    async () => {\n      await promiseFunction()\n    },\n    // Optional: catch error\n    (err) => {\n      console.error(err)\n    },\n    // dependency list\n    []\n  )\n\n  return (\n    <div>\n      <button onClick={() => sampleCallback()}>Fire</button>\n    </div>\n  )\n}\n```\n\n- ###### useEffectAsync\n\n```typescript\nimport { useEffectAsync } from '@chengsokdara/react-hooks-async'\nimport { useState } from 'react'\n\nconst App = () => {\n  const [state, setState] = useState<boolean>(false)\n\n  useEffectAsync(\n    // will be wrapped in try catch\n    async () => {\n      const response = await callBackend()\n      setState(result.data)\n    },\n    // Optional: cleanup function when component unmounted\n    () => {\n      setState(undefined)\n    },\n    // Optional: catch error\n    (err) => {\n      console.error(err)\n    },\n    // dependency list\n    []\n  )\n\n  return (\n    <div>\n      <p>\n        <b>State:</b> {state}\n      </p>\n    </div>\n  )\n}\n```\n\n- ###### useMemoAsync\n\n```typescript\nimport { useMemoAsync } from '@chengsokdara/react-hooks-async'\n\nconst App = () => {\n  const memoizedValue = useMemoAsync(\n    // will be wrapped in try catch\n    async () => {\n      const response = await promiseFunction()\n      return response + 1\n    },\n    // Optional: catch error\n    (err) => {\n      console.error(err)\n    },\n    // dependency list\n    []\n  )\n\n  return (\n    <div>\n      <p>\n        <b>Value:</b> {memoizedValue}\n      </p>\n    </div>\n  )\n}\n```\n\n- ### Roadmap\n\n  - add useTransition\n  - add useLayoutEffect\n  - add useImperativeHandle\n\n---\n\n**_Contact me for web or mobile app development using React or React Native_**  \n[https://chengsokdara.github.io](https://chengsokdara.github.io)\n","readmeFilename":"README.md"}