Created
April 8, 2019 02:43
-
-
Save andregardi/fe1d836dc3b67e34e02fa3b461934cad to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import React from 'react'; | |
| import useGlobalHook from 'use-global-hook'; | |
| const initialState = { | |
| counter: 0, | |
| }; | |
| const actions = { | |
| addToCounter: (store, amount) => { | |
| const newCounterValue = store.state.counter + amount; | |
| store.setState({ counter: newCounterValue }); | |
| }, | |
| }; | |
| const useGlobal = useGlobalHook(React, initialState, actions); | |
| const App = () => { | |
| const [globalState, globalActions] = useGlobal(); | |
| return ( | |
| <div> | |
| <p> | |
| counter: | |
| {globalState.counter} | |
| </p> | |
| <button type="button" onClick={() => globalActions.addToCounter(1)}> | |
| +1 to global | |
| </button> | |
| </div> | |
| ); | |
| }; | |
| export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment