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
| <span | |
| onClick={() => completeAt(index)} | |
| style={{ textDecoration: item.isCompleted ? "line-through" : "initial"}}> | |
| {item.name} | |
| </span> |
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 React, { useState } from "react"; | |
| import { useRecoilState, atom } from "recoil"; | |
| const todoListState = atom({ | |
| key: "todoListState", | |
| default: [ | |
| { name: "Apples", isCompleted: false }, | |
| { name: "Eggs", isCompleted: false }, | |
| { name: "Butter", isCompleted: false }, | |
| ], |
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
| const todoListState = atom({ | |
| key: "todoListState", | |
| default: [ | |
| { name: "Apples", isCompleted: false }, | |
| { name: "Eggs", isCompleted: false }, | |
| { name: "Butter", isCompleted: false }, | |
| ], | |
| }); |
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 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); |
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
| const editItemAt = (index) => { | |
| const todos = [...todoList]; | |
| var item = prompt("Change item name", todoList[index]); | |
| todos[index] = item; | |
| setTodoList(todos); | |
| }; |
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 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); |
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
| {todoList.map((item, index) => ( | |
| <li key={item}> | |
| {item} <button onClick={() => deleteItemAt(index)}>Delete</button> | |
| </li> | |
| ))} |
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
| const deleteItemAt = (index) => { | |
| const todos = [...todoList]; | |
| todos.splice(index, 1); | |
| setTodoList(todos); | |
| }; |
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 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); |
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
| <button onClick={() => setTodoList((todos) => [...todos, todo])}>Add</button> |