{"id":18267901,"url":"https://github.com/dance2die/react-use-localstorage","last_synced_at":"2025-04-05T05:03:42.402Z","repository":{"id":33196619,"uuid":"154747600","full_name":"dance2die/react-use-localstorage","owner":"dance2die","description":"(seeking maintainers)  ⚓ React hook for using local storage","archived":false,"fork":false,"pushed_at":"2023-03-04T03:54:25.000Z","size":1136,"stargazers_count":171,"open_issues_count":5,"forks_count":32,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-29T04:04:41.731Z","etag":null,"topics":["localstorage","npm","npm-package","react","react-hook","react-hooks","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/react-use-localstorage","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/dance2die.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-25T22:57:47.000Z","updated_at":"2025-01-22T07:35:55.000Z","dependencies_parsed_at":"2024-11-05T11:51:16.419Z","dependency_job_id":null,"html_url":"https://github.com/dance2die/react-use-localstorage","commit_stats":{"total_commits":117,"total_committers":8,"mean_commits":14.625,"dds":"0.16239316239316237","last_synced_commit":"bbb123d49d13ecf1ef9a745cfcec9a45c55a8303"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dance2die%2Freact-use-localstorage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dance2die%2Freact-use-localstorage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dance2die%2Freact-use-localstorage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dance2die%2Freact-use-localstorage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dance2die","download_url":"https://codeload.github.com/dance2die/react-use-localstorage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247289409,"owners_count":20914464,"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","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":["localstorage","npm","npm-package","react","react-hook","react-hooks","typescript"],"created_at":"2024-11-05T11:29:21.737Z","updated_at":"2025-04-05T05:03:42.386Z","avatar_url":"https://github.com/dance2die.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-use-localstorage\n\n[![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors)\n\n_depends on stable v16.8.1~_\n\n![version](https://img.shields.io/npm/v/react-use-localstorage.svg?style=flat-square)\n![size](https://img.shields.io/bundlephobia/min/react-use-localstorage.svg?style=flat-square)\n![minzippedsize](https://img.shields.io/bundlephobia/minzip/react-use-localstorage.svg?style=flat-square)\n\nAccess [Local Storage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) using [React hooks](https://reactjs.org/docs/hooks-intro.html).\n\nFork it on CodeSandbox  \n[![Edit usestate-useeffect](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/09xj95vxl)\n\n## How to use it\n\n```javascript\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport useLocalStorage from 'react-use-localstorage';\n\nimport './styles.css';\n\nfunction App() {\n  const [item, setItem] = useLocalStorage('name', 'Initial Value');\n\n  return (\n    \u003cdiv className=\"App\"\u003e\n      \u003ch1\u003eSet Name to store in Local Storage\u003c/h1\u003e\n      \u003cdiv\u003e\n        \u003clabel\u003e\n          Name:{' '}\n          \u003cinput\n            type=\"text\"\n            placeholder=\"Enter your name\"\n            value={item}\n            onChange={(e) =\u003e setItem(e.target.value)}\n          /\u003e\n        \u003c/label\u003e\n      \u003c/div\u003e\n    \u003c/div\u003e\n  );\n}\n\nconst rootElement = document.getElementById('root');\nReactDOM.render(\u003cApp /\u003e, rootElement);\n```\n\n### Note for SSR (server-side rendering)\n\nIf you are using Gatsby or other SSR frameworks, such as Next.js, refer to [this workaround](https://github.com/dance2die/react-use-localstorage/issues/24#issuecomment-581479939) by @hencatsmith.\n\nYou need to make sure that `window` is available.\n\n```js\nconst useSsrLocalStorage = (\n  key: string,\n  initial: string\n): [string, React.Dispatch\u003cstring\u003e] =\u003e {\n  return typeof window === 'undefined'\n    ? [initial, (value: string) =\u003e undefined]\n    : useLocalStorage(key, initial);\n};\n```\n\n## Demo\n\n![demo](https://github.com/dance2die/react-use-localstorage/raw/master/react-use-localstorage.gif)\n\n## Changelog\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eExpand Changelog\u003c/b\u003e\u003c/summary\u003e\n\n3.4.0\n\nThis version \"Watch changes on storage and change state\".  \nReference: https://github.com/dance2die/react-use-localstorage/pull/30\n\nThank you @VitorLuizC for the PR and @Svish for the review.\n\n3.3.0\n\nReverted the implementation of `setValue` to set `localStorage` value directly, instead of depending on `useEffect`.  \nReference: window.localstorage updated after value managed by useLocalStorage #29\n\n3.2.1\n\nThe library is covered by test.\nThank you so much, @SeanMcP~\n\n3.0.0\n\nDecided to go with @TheAifam5 the following breaking change as the type is derived from React type definition.\n\n- Breadking change: `setIteme` type is changed from `(item: string) =\u003e void` () to `React.Dispatch\u003cstring\u003e`\n- Updated infrastructure by @TheAifam5 🙏 in [PR #13](https://github.com/dance2die/react-use-localstorage/pull/13)\n\n  - Dropped babel in favor of `tsc` + `uglifyjs`\n  - Replaced npm with yarn\n  - Added husky for pre-commit git hooks\n  - Source map has been dropped from distribution\n  - distribution is moved from `dist` to `lib` folder\n\n    2.4.1\n\n- Added `useLocalStorage` return type explicitly to generate correct `index.d.ts` typing file.\n\n  2.4.0\n\n- Added TypeScript typings as suggested by @TheAifam5 in Issue #9\n\n  2.3.0\n\n- Fixed a bug where initial value is returned all the time #7 by @lilasquared 🙏\n\n  2.2.0\n\n- Sets initial value in local storage\n\n  2.1.0\n\n- Can optionally pass an initial value\n- This is to prevent form field from being uncontrolled.\n\n  2.0.0\n\n- Breaking change - `setItem` doesn't require `key`\n\n  1.1.1\n\n- Updated to React v16.8.1, which contains the patched Hooks\n\n  1.1.0\n\n- Updated dev dependency version\n\n  1.0.0\n\n- Updated to React v16.8.0, which contains the stable Hooks\n\n  0.0.6\n\n- Changed the language from JavaScript to TypeScript\n- It has minimized the distribution file greatly\n  \u003c/details\u003e\n\n## Contributors\n\nThanks goes to these wonderful people ([emoji key](https://github.com/all-contributors/all-contributors#emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/lilasquared\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/3036779?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eAaron Roberts\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#ideas-lilasquared\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e \u003ca href=\"https://github.com/dance2die/react-use-localstorage/issues?q=author%3Alilasquared\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"https://github.com/dance2die/react-use-localstorage/commits?author=lilasquared\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://twitter.com/dance2die\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/8465237?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eSung Kim\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/dance2die/react-use-localstorage/commits?author=dance2die\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/dance2die/react-use-localstorage/issues?q=author%3Adance2die\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"https://github.com/dance2die/react-use-localstorage/commits?author=dance2die\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://theaifam5.eu/\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/2192274?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eTheAifam5\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#ideas-TheAifam5\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e \u003ca href=\"https://github.com/dance2die/react-use-localstorage/commits?author=TheAifam5\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#infra-TheAifam5\" title=\"Infrastructure (Hosting, Build-Tools, etc)\"\u003e🚇\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"http://vitorluizc.github.io\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/9027363?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eVitor Luiz Cavalcanti\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/dance2die/react-use-localstorage/commits?author=VitorLuizC\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://seanmcp.com\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/6360367?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eSean McPherson\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/dance2die/react-use-localstorage/commits?author=SeanMcP\" title=\"Tests\"\u003e⚠️\u003c/a\u003e \u003ca href=\"https://github.com/dance2die/react-use-localstorage/commits?author=SeanMcP\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://www.geekality.net\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/142162?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eTorleif Berger\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/dance2die/react-use-localstorage/pulls?q=is%3Apr+reviewed-by%3ASvish\" title=\"Reviewed Pull Requests\"\u003e👀\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/evgenymarkov\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/16443248?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eEvgeny Markov\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/dance2die/react-use-localstorage/issues?q=author%3Aevgenymarkov\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"#ideas-evgenymarkov\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-enable --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdance2die%2Freact-use-localstorage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdance2die%2Freact-use-localstorage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdance2die%2Freact-use-localstorage/lists"}