Created
February 8, 2019 00:21
-
-
Save ctrlplusb/ac59843d2a0fe9b74242178392cf910c 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 { useState } from "react"; | |
import { useStore, useActions } from "./hooks"; // π | |
export default function Todos() { | |
// π pull out state from our store | |
const items = useStore(state => state.todos.items); | |
// π pull out actions from our store | |
const add = useActions(actions => actions.todos.add); | |
const [newTodo, setNewTodo] = useState(""); | |
return ( | |
<div> | |
<ul> | |
{items.map((todo, idx) => | |
<li key={idx}>{todo}</li> | |
)} | |
</ul> | |
<input | |
type="text" | |
onChange={e => setNewTodo(e.target.value)} | |
value={newTodo} | |
/> | |
<button onClick={() => add(newTodo)}>Add</button> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment