Ideas on persistence
See original GitHub issueFirst off: awesome library! No deps, simple, clean, love it! ❤️
Are there any ideas for persistence? Right now I’m doing this and it works pretty good 💪
import { createStore } from 'react-hooks-global-state'
import { DispatchedAction } from './actions'
import reducer from './reducer'
export type State = {
counter: number
}
const persistenceKey = 'my_cool_app_persistence'
const firstState: State = { counter: 0 }
const initialStringFromStorage = localStorage.getItem(persistenceKey)
const initialState: State = initialStringFromStorage === null
? firstState
: JSON.parse(initialStringFromStorage)
const persistentReducer = (state: State, action: DispatchedAction) => {
const mutated: State = reducer(state, action)
localStorage.setItem(persistenceKey, JSON.stringify(mutated))
return mutated
}
export const { GlobalStateProvider, dispatch, useGlobalState } = createStore(persistentReducer, initialState)
Maybe one could do a small github wiki entry and link it in the README. Any thoughts/ideas?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
39 You Can Do It | persistence, habits of mind, picture book
... Lauren Minehan's board "You Can Do It - Persistence", followed by 337 people on Pinterest. See more ideas about persistence, habits of...
Read more >23 Best Persistence Examples - Helpful Professor
23 Best Persistence Examples · 1. JK Rowling and Harry Potter · 2. Thomas Edison and the Lightbulb · 3. Van Gough's Paintings...
Read more >What Are Persistence Skills? (With Examples) - Zippia
You can improve your persistence by articulating your vision, learning to work hard, being an effective communicator, and thinking critically.
Read more >11 Ways to Promote Persistence - | Karen Tui Boyes Speaker
Create a culture in your classroom and school where it is OK to be different, to give new ideas a whirl and where...
Read more >4 Free Persistence & Grit Activities - VentureLab ...
Practice learning a new song on your instrument even though it's really hard. · Revise a story you wrote to make the ending...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Maybe you can link it in the main README, so people can find it easily 😃
https://github.com/dai-shi/react-hooks-global-state/wiki/Ideas
@CupCakeArmy The wiki is set up. Free free to edit it. I will add the link once we have several contents.