-
Notifications
You must be signed in to change notification settings - Fork 1
/
me-transforme-em-funcao.js
54 lines (43 loc) · 1.41 KB
/
me-transforme-em-funcao.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
import React, { useState, useEffect } from 'react';
import { Form, Button } from 'semantic-react-ui'
function ExampleComponent(props) {
const [showForm, setShowForm] = useState(false)
const [email, setEmail] = useState("")
const [name, setName] = useState(props.name)
useEffect(() => {
/* algum fetch de dado que a gente quer rodar somente uma vez
....................
*/
}, [])
const handleSubmit = (e) => {
e.preventDefault()
/* executa alguma request
....................
*/
}
const toggleShowForm = (e) => {
this.setState({
showForm: !setShowForm,
})
}
// RENDERS ------------------------------
const renderForm = () => {
return <Form onSubmit={handleSubmit}>
<Form.Input name="name" value={name} onChange={e => setName(e.target.value)} />
<Form.Input name="email" value={email} onChange={e => setEmail(e.target.value)} />
<Form.Button type="submit">Submit!</Form.Button>
</Form>
}
// RENDER --------------------------------
return (
<div >
{showForm ? this.renderForm()
: <Fragment>
<h3>Hi, {name}</h3>
<Button onClick={toggleShowForm} >Enter Email Address!</Button>
</Fragment>
}
</div>
)
}
export default ExampleComponent