{"id":13450323,"url":"https://github.com/daniel-dx/nice-hooks","last_synced_at":"2025-10-16T16:34:35.131Z","repository":{"id":38455090,"uuid":"210256196","full_name":"daniel-dx/nice-hooks","owner":"daniel-dx","description":"🍹 A lot of nice hooks to make react hooks easier to use ( useState callback / life cycle / instance variable)","archived":false,"fork":false,"pushed_at":"2023-05-28T13:36:28.000Z","size":509,"stargazers_count":47,"open_issues_count":1,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-14T18:28:18.465Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daniel-dx.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":"daniel-dx","patreon":"ncform","custom":"https://paypal.me/danieldx666"}},"created_at":"2019-09-23T03:22:35.000Z","updated_at":"2024-11-01T03:41:05.000Z","dependencies_parsed_at":"2024-01-07T18:05:55.663Z","dependency_job_id":"7d95396b-ce34-4dd4-a629-c65d49dc6947","html_url":"https://github.com/daniel-dx/nice-hooks","commit_stats":{"total_commits":23,"total_committers":3,"mean_commits":7.666666666666667,"dds":0.3913043478260869,"last_synced_commit":"7f0469442e09754fd3617763d2b63a55346d37fd"},"previous_names":["daniel-dx/use-state-cb"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/daniel-dx/nice-hooks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-dx%2Fnice-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-dx%2Fnice-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-dx%2Fnice-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-dx%2Fnice-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daniel-dx","download_url":"https://codeload.github.com/daniel-dx/nice-hooks/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-dx%2Fnice-hooks/sbom","scorecard":{"id":319191,"data":{"date":"2025-08-11","repo":{"name":"github.com/daniel-dx/nice-hooks","commit":"ac90a8d8bc9f14f1fefaf94f1e46e7b8126b884e"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/25 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 2 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"27 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-434g-2637-qmqr","Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m","Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw","Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p","Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747","Warn: Project is vulnerable to: GHSA-vjh7-7g9h-fjfh","Warn: Project is vulnerable to: GHSA-2j2x-2gpw-g8fm","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j","Warn: Project is vulnerable to: GHSA-h7cp-r72f-jxh6","Warn: Project is vulnerable to: GHSA-v62p-rq8g-8h59","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-52f5-9888-hmc6","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-18T00:57:59.509Z","repository_id":38455090,"created_at":"2025-08-18T00:57:59.509Z","updated_at":"2025-08-18T00:57:59.509Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271027689,"owners_count":24687081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T07:00:33.607Z","updated_at":"2025-10-16T16:34:30.097Z","avatar_url":"https://github.com/daniel-dx.png","language":"JavaScript","funding_links":["https://github.com/sponsors/daniel-dx","https://patreon.com/ncform","https://paypal.me/danieldx666"],"categories":["Packages"],"sub_categories":[],"readme":"# 🍹Nice Hooks\n\n[中文版](README_CN.md)\n\nA lot of nice hooks to make react hooks easier to use.\n\n\u003e If you find this project is useful to you, please give me a star.\n\n## Installation\n\n`npm install nice-hooks`\n\n## Hooks\n\n- [useStateCB](#useStateCB)\n\nLets you safely use the state of the react , whose value is the value you want, not the stale value. And also has the ability to callback.\n\n- [useSingleState (recommended)](#useSingleState)\n\nUse `state` with a way like `this.state` and `this.setState` in the form of `class`. It is also safe to use state and have callback capabilities\n\n- [useLifeCycle](#useLifeCycle)\n\nSupport lifecycle declarations to make code organization more readable, rather than using a bunch of useEffect.\n\n- [useInstanceVar](#useInstanceVar)\n\nSupport for instance variables. That is, after each re-render, the latest value of the variable can be obtained.\n\n- [useSingleInstanceVar (recommended)](#useSingleInstanceVar)\n\n(Recommended) Declare all instance variables together and use them closer to the instance variables\n\n## Usage\n\n### useStateCB\n\nLets you safely use the state of the react , whose value is the value you want, not the stale value. And also has the ability to callback.\n\n```\n# Example\n\nimport React from 'react';\n\nimport { useStateCB } from 'nice-hooks';\n\nexport const UseStateCBDemoComp = () =\u003e {\n  const [getCount, setCount] = useStateCB(0);\n\n  function doSomeActions() {\n    console.log('Current count:', getCount());\n  }\n\n  return (\n    \u003cdiv\u003e\n      \u003cp\u003e{getCount()}\u003c/p\u003e\n\n      \u003cbutton type=\"button\" onClick={() =\u003e setCount(getCount() + 1, doSomeActions)}\u003e\n        Increase\n      \u003c/button\u003e\n    \u003c/div\u003e\n  );\n};\n```\n\n### useSingleState\n\n(Recommended) Use `state` with a way like `this.state` and `this.setState` in the form of `class`. It is also safe to use state and have callback capabilities\n\n```\n# Example\n\nimport React from \"react\";\n\nimport { useSingleState } from \"nice-hooks\";\n\nexport const UseSingleStateDemoComp = () =\u003e {\n  const [state, setState] = useSingleState({\n    count: 0,\n    time: +new Date()\n  });\n\n  function doSomeActions() {\n    console.log(\"Current count:\", state.count);\n  }\n\n  return (\n    \u003cdiv\u003e\n      \u003ch2\u003euseSingleState\u003c/h2\u003e\n\n      \u003cp\u003e{state.count} {state.time}\u003c/p\u003e\n\n      \u003cbutton\n        type=\"button\"\n        onClick={() =\u003e\n          setState(\n            {\n              count: state.count + 1\n            },\n            doSomeActions\n          )\n        }\n      \u003e\n        Increase\n      \u003c/button\u003e\n      \u003cbutton type=\"button\"\n        onClick={() =\u003e\n          setState({\n            time: +new Date()\n          })\n        }\n      \u003e\n        Chnange Time\n      \u003c/button\u003e\n    \u003c/div\u003e\n  );\n};\n```\n\n### useLifeCycle\n\nSupport lifecycle declarations to make code organization more readable, rather than using a bunch of useEffect.\n\n```\n# Example\n\nimport React from 'react';\n\nimport { useLifeCycle } from 'nice-hooks';\n\nconst App = () =\u003e {\n  \n  useLifeCycle({\n\n    didMount() {\n      // Do something after mounted\n    },\n\n    willUnmount() {\n      // Do something when the component will be unmount\n    },\n\n    didUpdate() {\n      // Do something after re-rendered.\n    },\n\n    didMountAndWillUnmount: [\n      {\n        didMount() {\n          // Example: setTimeout\n        },\n        willUnmount() {\n          // Example: clearTimeout\n        }\n      },\n      {\n        didMount() {\n          // Example: on resize event\n          // ...\n        },\n        willUnmount() {\n          // Example: off resize event \n          // ...\n        }\n      }\n    ]\n  })\n\n  return (\n    \u003cdiv\u003e\u003c/div\u003e\n  );\n};\n```\n\n### useInstanceVar\n\nSupport for instance variables. That is, after each re-render, the latest value of the variable can be obtained.\n\n```\n# Example\n\nimport React from \"react\";\n\nimport { useInstanceVar, useSingleState } from \"nice-hooks\";\n\nexport const UseInstanceVarDemoComp = () =\u003e {\n  const [getIntervalVal, setIntervalVal] = useInstanceVar(null);\n\n  const [state, setState] = useSingleState({ count: 0 });\n\n  function start() {\n    const interval = setInterval(\n      () =\u003e setState({ count: state.count + 1 }),\n      1000\n    );\n    setIntervalVal(interval);\n  }\n\n  function stop() {\n    const interval = getIntervalVal();\n    interval \u0026\u0026 clearInterval(interval);\n  }\n\n  return (\n    \u003cdiv\u003e\n      \u003cp\u003e{state.count}\u003c/p\u003e\n      \u003cbutton onClick={start}\u003eStart\u003c/button\u003e\n      \u003cbutton onClick={stop}\u003eStop\u003c/button\u003e\n    \u003c/div\u003e\n  );\n};\n```\n\n### useSingleInstanceVar\n\n(Recommended) Declare all instance variables together and use them closer to the instance variables\n\n```\n# Example\n\nimport React from \"react\";\n\nimport { useSingleInstanceVar, useSingleState } from \"nice-hooks\";\n\nexport const UseSingleInstanceVarDemoComp = () =\u003e {\n  const instanceVal = useSingleInstanceVar({\n    interval: null\n  });\n\n  const [state, setState] = useSingleState({ count: 0 });\n\n  function start() {\n    instanceVal.interval = setInterval(\n      () =\u003e setState({ count: state.count + 1 }),\n      1000\n    );\n  }\n\n  function stop() {\n    const interval = instanceVal.interval;\n    interval \u0026\u0026 clearInterval(interval);\n  }\n\n  return (\n    \u003cdiv\u003e\n      \u003cp\u003e{state.count}\u003c/p\u003e\n      \u003cbutton type=\"button\" onClick={start}\u003eStart\u003c/button\u003e\n      \u003cbutton type=\"button\" onClick={stop}\u003eStop\u003c/button\u003e\n    \u003c/div\u003e\n  );\n};\n```\n\n## Contribute\n\n* `git clone https://github.com/daniel-dx/nice-hooks.git`\n* `cd nice-hooks`\n* `npm install`\n* `npm run test`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaniel-dx%2Fnice-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaniel-dx%2Fnice-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaniel-dx%2Fnice-hooks/lists"}