Last active
February 26, 2021 15:19
-
-
Save JaysonChiang/1396f733d468bc658b92186841becf5e to your computer and use it in GitHub Desktop.
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'; | |
const TodoList: React.FC = () => { | |
const [todo, setTodo] = useState(''); | |
const [todos, setTodos] = useState<string[]>([]); | |
const onClick = () => { | |
setTodo(''); | |
setTodos([...todos, todo]); | |
}; | |
return ( | |
<div> | |
<input value={todo} onChange={(e) => setTodo(e.target.value)} /> | |
<button onClick={onClick}>Add Todo</button> | |
{todos.map((todo) => (<div>{todo}</div>))} | |
</div> | |
); | |
}; | |
export default TodoList; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment