-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
60 lines (43 loc) · 1.09 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { useState, useEffect } from 'react';
function App(){
const [input, setInput] = useState('');
const [tarefas, setTarefas] = useState([
'Pagar a conta de luz',
'Estudar React JS'
]);
useEffect(()=>{
const tarefasStorage = localStorage.getItem('@tarefa');
if(tarefasStorage){
setTarefas(JSON.parse(tarefasStorage))
}
}, []);
useEffect(()=>{
localStorage.setItem('@tarefa', JSON.stringify(tarefas))
}, [tarefas]);
function handleRegister(e){
e.preventDefault();
setTarefas([...tarefas, input]);
setInput('');
}
return(
<div>
<h1>Cadastrando usuario</h1>
<form onSubmit={handleRegister}>
<label>Nome da tarefa:</label><br/>
<input
placeholder="Digite uma tarefa"
value={input}
onChange={ (e) => setInput(e.target.value) }
/><br/>
<button type="submit">Registrar</button>
</form>
<br/><br/>
<ul>
{tarefas.map( tarefa => (
<li key={tarefa}>{tarefa}</li>
))}
</ul>
</div>
);
}
export default App;