Created
December 7, 2019 17:30
-
-
Save zaguiini/1e8d1f7e0dcab85a6a98c307c42e62be 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 { createStore } from 'easy-peasy' | |
const store = createStore({ | |
todos: { | |
items: ['Create store', 'Wrap application', 'Use store'], | |
add: action((state, payload) => { | |
state.items.push(payload) | |
}) | |
} | |
}) | |
const TodoList = () => { | |
const todos = useStoreState(state => state.todos.items) | |
const add = useStoreActions(actions => actions.todos.add) | |
return ( | |
<div> | |
{todos.map((todo, idx) => <div key={idx}>{todo}</div>)} | |
<AddTodo onAdd={add} /> | |
</div> | |
) | |
} | |
const App = () => { | |
return ( | |
<StoreProvider store={store}> | |
<TodoList /> | |
</StoreProvider> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment