question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ideas on persistence

See original GitHub issue

First 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cupcakearmycommented, Jan 26, 2019

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

1reaction
dai-shicommented, Jan 25, 2019

@CupCakeArmy The wiki is set up. Free free to edit it. I will add the link once we have several contents.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found