Skip to content

Instantly share code, notes, and snippets.

@ozcanzaferayan
Created May 19, 2020 16:02
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 ozcanzaferayan/22ebe09c35389977eb0fdc0329196173 to your computer and use it in GitHub Desktop.
Save ozcanzaferayan/22ebe09c35389977eb0fdc0329196173 to your computer and use it in GitHub Desktop.
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