Created
November 23, 2020 08:30
-
-
Save JimmyLv/e293dd22d1e78108d794763f51f2fbd2 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
| function App() { | |
| const [todos, setTodos] = useState([ | |
| { id: 1, title: "Selectus aut autem", completed: false }, | |
| { id: 2, title: "Luis ut nam facilis et officia qui", completed: false }, | |
| { id: 3, title: "Fugiat veniam minus", completed: false }, | |
| { id: 4, title: "Aet porro tempora", completed: true }, | |
| { id: 5, title: "Laboriosam mollitia et enim quasi", completed: false } | |
| ]); | |
| const changeInput = (e) => {todos.map(items => items.id === parseInt(e.target.value) && (items.completed = e.target.checked)); | |
| setTodos([...todos], todos);} | |
| return ( | |
| <div className="container"> | |
| {todos.map(items => { | |
| return ( | |
| <div key={items.id}> | |
| <label> | |
| <input type="checkbox" | |
| onChange={changeInput} | |
| value={items.id} | |
| checked={items.completed} /> {items.title}</label> | |
| </div> | |
| ) | |
| })} | |
| </div> | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment