https://github.com/jwebcoder/recost-persist
persists application state into localstorage using recost
https://github.com/jwebcoder/recost-persist
Last synced: 5 months ago
JSON representation
persists application state into localstorage using recost
- Host: GitHub
- URL: https://github.com/jwebcoder/recost-persist
- Owner: JWebCoder
- License: mit
- Created: 2018-10-28T17:10:32.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T16:21:48.000Z (over 3 years ago)
- Last Synced: 2025-03-15T05:16:24.605Z (over 1 year ago)
- Language: JavaScript
- Size: 536 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# recost-persist
Recost middleware to persist application state into localstorage on state changes
## Instalation
`npm install --save recost-persist`
## Usage
```js
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import initContext, { Provider } from 'recost'
import { persister, reloadPersistedState } from 'recost-persist'
import reducer from './reducer'
// define the initial state for the application
const initialState = {
// ...
}
const STATE_KEY = 'APP_STATE'
// get the stored application state
let state = reloadPersistedState(STATE_KEY, initialState)
/*
* inicialize the context with the obtained state
* add the persister middleware with a STATE_KEY
*/
initContext(state, reducer, [persister(STATE_KEY)])
// and just render :)
ReactDOM.render(
,
document.getElementById('root')
);
```