Skip to content
Permalink
Browse files

submit button

  • Loading branch information...
rwieruch committed Apr 6, 2019
1 parent 3e6e5a2 commit 37144e9ef12bb3c46ed509e26e7ab49c46cfa3d5
Showing with 24 additions and 5 deletions.
  1. +24 −5 src/App.js
@@ -1,41 +1,60 @@
import React, { useState } from 'react';
import uuid from 'uuid/v4';

const initalTodos = [
{
id: 'a',
id: uuid(),
task: 'Learn React',
complete: true,
},
{
id: 'b',
id: uuid(),
task: 'Learn Firebase',
complete: true,
},
{
id: 'c',
id: uuid(),
task: 'Learn GraphQL',
complete: false,
},
];

const App = () => {
const [todos, setTodos] = useState(initalTodos);
const [task, setTask] = useState('');

const handleChangeInput = event => {
setTask(event.target.value);
};

const handleSubmit = event => {
if (task) {
setTodos(todos.concat({ id: uuid(), task, complete: false }));
}

setTask('');

event.preventDefault();
};

return (
<div>
<ul>
{initalTodos.map(todo => (
{todos.map(todo => (
<li key={todo.id}>
<label>{todo.task}</label>
</li>
))}
</ul>

<input type="text" value={task} onChange={handleChangeInput} />
<form onSubmit={handleSubmit}>
<input
type="text"
value={task}
onChange={handleChangeInput}
/>
<button type="submit">Add Todo</button>
</form>
</div>
);
};

0 comments on commit 37144e9

Please sign in to comment.
You can’t perform that action at this time.