Skip to content

Instantly share code, notes, and snippets.

@zaguiini
Created December 7, 2019 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zaguiini/1e8d1f7e0dcab85a6a98c307c42e62be to your computer and use it in GitHub Desktop.
Save zaguiini/1e8d1f7e0dcab85a6a98c307c42e62be to your computer and use it in GitHub Desktop.
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