Created
May 19, 2020 16:02
-
-
Save ozcanzaferayan/22ebe09c35389977eb0fdc0329196173 to your computer and use it in GitHub Desktop.
This file contains 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, { useState } from "react"; | |
import { useSetRecoilState } from "recoil"; | |
import { todoListState } from "../state/atoms"; | |
export function TodoItemCreator() { | |
const [todo, setTodo] = useState({ name: "" }); | |
const setTodoList = useSetRecoilState(todoListState); | |
return ( | |
<> | |
<input | |
value={todo.name} | |
onChange={(e) => setTodo({ name: e.target.value })} | |
/> | |
<button onClick={() => setTodoList((todos) => [...todos, todo])}> | |
Add | |
</button> | |
</> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment