Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import React, { useState } from "react";
const Todo = () => {
const [todoName, setTodoName] = useState("");
const [todoList, setTodoList] = useState<string[]>([]);
const inputChangeHandler = (evt: React.ChangeEvent<HTMLInputElement>) => {
setTodoName(evt.target.value);
};
const todoAddHandler = () => {
//we need to add it to our list
};
return (
<React.Fragment>
<input
type="text"
placeholder="Todo"
onChange={inputChangeHandler}
value={todoName}
/>
<button type="submit" onClick={todoAddHandler}>
Add
</button>
<ul>
{todoList.map((todo: string) => (
<ul key={todo}>{todo}</ul>
))}
</ul>
</React.Fragment>
);
};
export default Todo;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.