Last active
February 4, 2019 14:58
-
-
Save tannerlinsley/490272e89c9a822eb3819e97dd5759c1 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 { StoreProvider, useStore } from './store' | |
const Counter = () => { | |
// Use the store | |
const [state, setState] = useStore(); | |
const increment = () => | |
setState(old => ({ | |
...old, | |
count: old.count + 1 | |
})); | |
const decrement = () => | |
setState(old => ({ | |
...old, | |
count: old.count - 1 | |
})); | |
return ( | |
<div> | |
<button onClick={decrement}>-</button> | |
{state.count} | |
<button onClick={increment}>+</button> | |
</div> | |
); | |
}; | |
const App = () => { | |
return ( | |
// Provide the store to the app | |
<StoreProvider initialValue={{ count: 0 }}> | |
<Counter /> | |
</StoreProvider> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment