Last active
March 22, 2023 11:11
-
-
Save juhahinkula/cae3b6c541238ed4336a4fbc3e6b75e5 to your computer and use it in GitHub Desktop.
Simple todolist made with create-react-app. Gist contains the App.js code
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 { useState } from 'react'; | |
function TodoList() { | |
const [desc, setDesc] = useState(''); | |
const [todos, setTodos] = useState([]); | |
const inputChanged = (event) => { | |
setDesc(event.target.value); | |
} | |
const addTodo = (event) => { | |
event.preventDefault(); | |
setTodos([...todos, desc]); | |
} | |
return ( | |
<> | |
<input type="text" onChange={inputChanged} value={desc}/> | |
<button onClick={addTodo}>Add</button> | |
<table> | |
<tbody> | |
{ | |
todos.map(todo => <tr><td>{todo}</td></tr>) | |
} | |
</tbody> | |
</table> | |
</> | |
); | |
}; | |
export default Todolist; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment