Created
October 31, 2018 20:01
-
-
Save jhonnymichel/d856cf34197322e5281e167c3dde14c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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