{"id":28281585,"url":"https://github.com/phantomstudios/use-local-state","last_synced_at":"2025-10-15T15:09:47.668Z","repository":{"id":38473183,"uuid":"343088046","full_name":"phantomstudios/use-local-state","owner":"phantomstudios","description":"A simple React hook that allows you to store data within LocalStorage with the same interface as the standard React.useState hook.","archived":false,"fork":false,"pushed_at":"2025-10-01T16:04:01.000Z","size":1674,"stargazers_count":2,"open_issues_count":7,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-10-03T12:07:44.964Z","etag":null,"topics":["hook","localstorage","react","state"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/phantomstudios.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":"SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-02-28T11:27:55.000Z","updated_at":"2025-09-02T08:16:46.000Z","dependencies_parsed_at":"2025-04-30T12:47:31.041Z","dependency_job_id":"4f9ad519-82f6-4e80-9b01-9fb75ddce6f7","html_url":"https://github.com/phantomstudios/use-local-state","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/phantomstudios/use-local-state","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phantomstudios%2Fuse-local-state","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phantomstudios%2Fuse-local-state/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phantomstudios%2Fuse-local-state/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phantomstudios%2Fuse-local-state/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phantomstudios","download_url":"https://codeload.github.com/phantomstudios/use-local-state/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phantomstudios%2Fuse-local-state/sbom","scorecard":{"id":730572,"data":{"date":"2025-08-11","repo":{"name":"github.com/phantomstudios/use-local-state","commit":"3b094e8c3508905b0382b020a1998c8b7454acb8"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":7.3,"checks":[{"name":"Code-Review","score":10,"reason":"all changesets reviewed","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":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","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":"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":"Maintained","score":10,"reason":"13 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"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":"Pinned-Dependencies","score":3,"reason":"dependency not pinned by hash detected -- score normalized to 3","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npmpublish.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/phantomstudios/use-local-state/npmpublish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npmpublish.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/phantomstudios/use-local-state/npmpublish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npmpublish.yml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/phantomstudios/use-local-state/npmpublish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npmpublish.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/phantomstudios/use-local-state/npmpublish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/phantomstudios/use-local-state/test.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/phantomstudios/use-local-state/test.yml/master?enable=pin","Info:   0 out of   6 GitHub-owned GitHubAction dependencies pinned","Info:   3 out of   3 npmCommand dependencies pinned"],"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":"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":"Token-Permissions","score":9,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Info: jobLevel 'contents' permission set to 'read': .github/workflows/npmpublish.yml:12","Info: jobLevel 'contents' permission set to 'read': .github/workflows/npmpublish.yml:27","Info: jobLevel 'contents' permission set to 'read': .github/workflows/test.yml:10","Warn: no topLevel permission defined: .github/workflows/npmpublish.yml:1","Warn: no topLevel permission defined: .github/workflows/test.yml:1","Info: no jobLevel write permissions found"],"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":"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":"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":"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":"Branch-Protection","score":5,"reason":"branch protection is not maximal on development and all release branches","details":["Info: 'allow deletion' disabled on branch 'master'","Info: 'force pushes' disabled on branch 'master'","Info: 'branch protection settings apply to administrators' is required to merge on branch 'master'","Warn: 'stale review dismissal' is disabled on branch 'master'","Warn: required approving review count is 1 on branch 'master'","Info: codeowner review is required on branch 'master'","Warn: 'last push approval' is disabled on branch 'master'","Warn: no status checks found to merge onto branch 'master'","Info: PRs are required in order to make changes on branch 'master'"],"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":9,"reason":"SAST tool is not run on all commits -- score normalized to 9","details":["Warn: 27 commits out of 30 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":9,"reason":"1 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw"],"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-22T14:17:51.592Z","repository_id":38473183,"created_at":"2025-08-22T14:17:51.592Z","updated_at":"2025-08-22T14:17:51.592Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279085837,"owners_count":26100020,"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-10-15T02:00:07.814Z","response_time":56,"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":["hook","localstorage","react","state"],"created_at":"2025-05-21T12:13:17.214Z","updated_at":"2025-10-15T15:09:47.661Z","avatar_url":"https://github.com/phantomstudios.png","language":"TypeScript","readme":"# use-local-state\n\n[![NPM version][npm-image]][npm-url]\n[![Actions Status][ci-image]][ci-url]\n[![PR Welcome][npm-downloads-image]][npm-downloads-url]\n\nA simple React hook that allows you to store data within `LocalStorage` with the same interface as the standard `React.useState` hook.\n\n## Introduction\n\nJust swap out your `useState` calls with `useLocalState` to persist the data between refreshes. This hook is also SSR safe and does not break when used without `window` existing.\n\n```javascript\nimport useLocalState from \"@phntms/use-local-state\";\n\nconst [value, setValue, resetValue] = useLocalState(\"KEY\", \"\");\n```\n\n## Installation\n\nInstall this package with `npm`.\n\n```bash\nnpm i @phntms/use-local-state\n```\n\n## Usage\n\nStore a boolean to track if a user has accepted terms of use.\n\n```JSX\nimport React from 'react';\nimport useLocalState from '@phntms/use-local-state';\n\nconst TermsExample = () = {\n  const [accepted, setAccepted] = useLocalState(\"TERMS_ACCEPTED\", false);\n\n  return (\n    \u003c\u003e\n      \u003ch1\u003eWelcome\u003c/h2\u003e\n      {!accepted \u0026\u0026 \u003c\u003e\n        \u003cp\u003eDo you accept our terms?\u003c/p\u003e\n        \u003cbutton onClick={()=\u003esetAccepted(true)}\u003eAccept\u003c/button\u003e\n      \u003c/\u003e}\n    \u003c/\u003e\n  );\n}\n```\n\nStore a list of bookmarks.\n\n```JSX\nimport React from 'react';\nimport useLocalState from '@phntms/use-local-state';\n\ninterface Bookmark {\n  title: string;\n  url: string;\n}\n\nconst BookmarkExample = () = {\n  const [bookmarks, setBookmarks, clearBookmarks] = useLocalState\u003cBookmark[]\u003e(\"BOOKMARKS\", []);\n\n  const addBookmark = (bookmark: Bookmark) =\u003e setBookmarks([...bookmarks, bookmark]);\n\n  return (\n    \u003c\u003e\n      \u003ch1\u003eBookmarks\u003c/h2\u003e\n      \u003cNewBookmark add={addBookmark} /\u003e\n      \u003cbutton onClick={clearBookmarks}\u003eClear Bookmarks\u003c/button\u003e\n      \u003cul\u003e\n        {bookmarks.map(((bookmark, i) =\u003e (\n          \u003cli key={i}\u003e\n            \u003ca href={bookmark.url}\u003e{bookmark.title}\u003c/a\u003e\n          \u003c/li\u003e\n        )))}\n      \u003c/ul\u003e\n    \u003c/\u003e\n  );\n}\n```\n\n## API\n\n### Input\n\n- `key` : Required - The key of type `string` to store within `LocalStorage`.\n- `initialValue` : Required - The default/initial value of type `T` if the key is not found within the `LocalStorage` object.\n\n### Output\n\nAn array containing the value, a function to set the value and another function to reset the value.\n\n- `[0]` : The value of the data stored in LocalStorage or the defaultValue if not set.\n- `[1]` : A function to set the value stored in LocalStorage. Signature is exactly like the standard [React.useState](https://reactjs.org/docs/hooks-state.html) hook.\n- `[2]` : A function to reset the data stored in the LocalStorage.\n\n[npm-image]: https://img.shields.io/npm/v/@phntms/use-local-state.svg?style=flat-square\u0026logo=react\n[npm-url]: https://npmjs.org/package/@phntms/use-local-state\n[npm-downloads-image]: https://img.shields.io/npm/dm/@phntms/use-local-state.svg\n[npm-downloads-url]: https://npmcharts.com/compare/@phntms/use-local-state?minimal=true\n[ci-image]: https://github.com/phantomstudios/use-local-state/workflows/test/badge.svg\n[ci-url]: https://github.com/phantomstudios/use-local-state/actions\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphantomstudios%2Fuse-local-state","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphantomstudios%2Fuse-local-state","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphantomstudios%2Fuse-local-state/lists"}