Skip to content

Instantly share code, notes, and snippets.

@daniele-zurico
Created January 10, 2019 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daniele-zurico/83be5492c8b76549983ce078a69a865b to your computer and use it in GitHub Desktop.
Save daniele-zurico/83be5492c8b76549983ce078a69a865b to your computer and use it in GitHub Desktop.
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