Skip to content

Instantly share code, notes, and snippets.

@jhonnymichel
Created October 31, 2018 20:01
Show Gist options
  • Save jhonnymichel/d856cf34197322e5281e167c3dde14c4 to your computer and use it in GitHub Desktop.
Save jhonnymichel/d856cf34197322e5281e167c3dde14c4 to your computer and use it in GitHub Desktop.
export function useStore() {
const [ state, set ] = useState(store.state);
if (!store.setters.includes(set)) {
store.setters.push(set);
}
useEffect(() => () => {
store.setters = store.setters.filter(setter => setter !== set)
}, [])
return [ state, store.setState ];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment