Skip to content

Instantly share code, notes, and snippets.

@juhahinkula
Last active March 22, 2023 11:11
Show Gist options
  • Save juhahinkula/cae3b6c541238ed4336a4fbc3e6b75e5 to your computer and use it in GitHub Desktop.
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
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