{"id":13629971,"url":"https://github.com/roadmanfong/zustand-persist","last_synced_at":"2025-04-06T16:14:06.681Z","repository":{"id":42582290,"uuid":"291735327","full_name":"roadmanfong/zustand-persist","owner":"roadmanfong","description":"Persist and rehydrate state ","archived":false,"fork":false,"pushed_at":"2023-07-23T13:02:03.000Z","size":1637,"stargazers_count":120,"open_issues_count":17,"forks_count":13,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T15:08:15.023Z","etag":null,"topics":["react","react-native","zustand"],"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/roadmanfong.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}},"created_at":"2020-08-31T14:19:07.000Z","updated_at":"2025-02-12T04:37:32.000Z","dependencies_parsed_at":"2024-01-14T08:19:45.935Z","dependency_job_id":"44bb43d4-58d0-4c1c-9419-029e212584ed","html_url":"https://github.com/roadmanfong/zustand-persist","commit_stats":{"total_commits":60,"total_committers":7,"mean_commits":8.571428571428571,"dds":"0.23333333333333328","last_synced_commit":"856230c78c707263f4afb8014e446e6e928785c5"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roadmanfong%2Fzustand-persist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roadmanfong%2Fzustand-persist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roadmanfong%2Fzustand-persist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roadmanfong%2Fzustand-persist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/roadmanfong","download_url":"https://codeload.github.com/roadmanfong/zustand-persist/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247509237,"owners_count":20950232,"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":["react","react-native","zustand"],"created_at":"2024-08-01T22:01:26.135Z","updated_at":"2025-04-06T16:14:06.655Z","avatar_url":"https://github.com/roadmanfong.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"⚠️ This project is no longer being maintained ⚠️\n\nZustand now has built in persistence middleware, so has persist functionality out of the box. Read more in the [Zustand readme](https://github.com/pmndrs/zustand#persist-middleware).\n\n# Zustand persist\n\nPersist and rehydrate state works on react and react native.\n\n[Zustand](https://github.com/react-spring/zustand) is a small, fast and scaleable bearbones state-management solution.\n\nThis library is inspired by [https://github.com/rt2zz/redux-persist](https://github.com/rt2zz/redux-persist).\n\nContributions are Welcome\n\n[![Build Status](https://travis-ci.org/roadmanfong/zustand-persist.svg?branch=master)](https://travis-ci.org/roadmanfong/zustand-persist) [![npm version](https://img.shields.io/npm/v/zustand-persist.svg?style=flat-square)](https://www.npmjs.com/package/zustand-persist) [![npm downloads](https://img.shields.io/npm/dm/zustand-persist.svg?style=flat-square)](https://www.npmjs.com/package/zustand-persist)\n\n```cli\n$ npm install zustand-persist\n$ yarn add zustand-persist\n```\n\nTry [Demo](https://codesandbox.io/s/zustand-persist-example-5u3ry?file=/src/App.js) Here\n\n## Middleware\n\n```ts\n// if in react native\n// import AsyncStorage from '@react-native-community/async-storage'\n\nconst { persist, purge } = configurePersist({\n  storage: localStorage, // use `AsyncStorage` in react native\n  rootKey: 'root', // optional, default value is `root`\n})\n\nconst useStore = createStore(\n  persist({\n    key: 'auth', // required, child key of storage\n    allowlist: ['isAuthenticated', 'user'], // optional, will save everything if allowlist is undefined\n    denylist: [], // optional, if allowlist set, denylist will be ignored\n  }, (set) =\u003e ({\n    isAuthenticating: false,\n    isAuthenticated: false,\n    user: undefined,\n    login: async (username, password) =\u003e{\n      set((state) =\u003e ({ isAuthenticating: true }))\n      const { user } = await webLogin(username, password)\n      set((state) =\u003e ({\n        isAuthenticated: true,\n        isAuthenticating: false,\n        user,\n      })),\n    }\n  }))\n)\n```\n\n## PersistGate\n\n```tsx\nfunction App() {\n  // Must call useStore to bootstrap persistence or will stop on loading screen\n  useStore()\n  return (\n    \u003cPersistGate\n      onBeforeLift={() =\u003e {\n        console.log('onBeforeLift')\n      }}\n      loading={\u003cLoading /\u003e}\u003e\n      \u003cAppContent /\u003e\n    \u003c/PersistGate\u003e\n  )\n}\n```\n\n## Limitations\nZustand allows any valid JavaScript data types to set in the store, such as Set, Map, or functions. Both `localStorage` and `AsyncStorage` require that all values set in them be serializable, or converted into string form for storage. This means if you wish to persist the contents of your store all of its values need to be serializable. Any values which are not serializable will be silently absent upon hydration.\n\nA note on storing actions (functions): your actions are safe as long as they exist in the initial state during store creation. The hydration process merges initial state with stored state.\n\n## Todo\n\n- enhanced removing root logic\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froadmanfong%2Fzustand-persist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froadmanfong%2Fzustand-persist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froadmanfong%2Fzustand-persist/lists"}