https://github.com/addono/react-persisted-global-state
Simple React hook for global, local storage persisted state
https://github.com/addono/react-persisted-global-state
github-actions global hooks local-storage npm persist react state
Last synced: about 2 months ago
JSON representation
Simple React hook for global, local storage persisted state
- Host: GitHub
- URL: https://github.com/addono/react-persisted-global-state
- Owner: Addono
- License: mit
- Created: 2023-01-02T12:35:23.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-13T09:21:04.000Z (about 1 year ago)
- Last Synced: 2024-04-13T22:12:45.574Z (about 1 year ago)
- Topics: github-actions, global, hooks, local-storage, npm, persist, react, state
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/react-persisted-global-state
- Size: 3.78 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# react-persisted-global-state
[](https://github.com/Addono/react-persisted-global-state/blob/master/LICENSE)
[](https://www.repostatus.org/#active)
[](https://depfu.com/github/Addono/react-persisted-global-state)
[](https://www.npmjs.com/package/react-persisted-global-state)
[](https://www.npmjs.com/package/react-persisted-global-state)
[](https://github.com/Addono/react-persisted-global-state/stargazers)
[](#contributors-)## About
Simple React hook for global state which is persisted to Local Storage.
This allows sharing state between multiple components or different instance of the same component, all while the changes are persisted to the browser's Local Storage.
## Installing
Install `react-persisted-global-state` and its peer-dependencies:
```bash
# For users of npm
npm install --save react-persisted-global-state react-use# For users of Yarn
yarn add react-persisted-global-state react-use
```## Usage
```tsx
import { createPersistedGlobalState } from 'react-persisted-global-state';// Register a re-usable instance of our global state store
const useMyPersistedGlobalState = createPersistedGlobalState(
'my-localstorage-key',
'Hello, world!'
);const MyComponent = () => {
const [state, setState, removeState] = useMyPersistedGlobalState();return (
setState(e.target.value)} onClear />
);
};
```## Releasing
We use [`release-it`](https://github.com/release-it/release-it) to automate our creating releases for this application. A new release can be rolled out by running:
```bash
yarn release
```Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!