Skip to content

Instantly share code, notes, and snippets.

@ozcanzaferayan
Created May 19, 2020 14:20
Show Gist options
  • Save ozcanzaferayan/7b7c9dccbdcf19f02ee023aa0803c663 to your computer and use it in GitHub Desktop.
Save ozcanzaferayan/7b7c9dccbdcf19f02ee023aa0803c663 to your computer and use it in GitHub Desktop.
import React, { useState } from "react";
import { useRecoilState, atom } from "recoil";
const todoListState = atom({
key: "todoListState",
default: ["Apples", "Eggs", "Butter"],
});
function App() {
const [todoList, setTodoList] = useRecoilState(todoListState);
const [todo, setTodo] = useState("");
return (
<>
<input value={todo} onChange={(e) => setTodo(e.target.value)} />
<button onClick={() => setTodoList((todos) => [...todos, todo])}>
Add
</button>
{todoList.map((item) => (
<li key={item}>{item}</li>
))}
</>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment