()
| 3 | |
| 4 | |
| 5 | export const SimpleForm = () => { |
| 6 | |
| 7 | const [formState, setFormState] = useState({ |
| 8 | username: 'strider', |
| 9 | email: 'fernando@google.com' |
| 10 | }); |
| 11 | |
| 12 | const { username, email } = formState; |
| 13 | |
| 14 | const onInputChange = ({ target }) => { |
| 15 | const { name, value } = target; |
| 16 | setFormState({ |
| 17 | ...formState, |
| 18 | [ name ]: value |
| 19 | }); |
| 20 | } |
| 21 | |
| 22 | |
| 23 | useEffect( () => { |
| 24 | // console.log('useEffect called!'); |
| 25 | }, []); |
| 26 | |
| 27 | useEffect( () => { |
| 28 | // console.log('formState changed!'); |
| 29 | }, [formState]); |
| 30 | |
| 31 | useEffect( () => { |
| 32 | // console.log('email changed!'); |
| 33 | }, [ email ]); |
| 34 | |
| 35 | |
| 36 | |
| 37 | return ( |
| 38 | <> |
| 39 | <h1>Formulario Simple</h1> |
| 40 | <hr /> |
| 41 | |
| 42 | <input |
| 43 | type="text" |
| 44 | className="form-control" |
| 45 | placeholder="Username" |
| 46 | name="username" |
| 47 | value={ username } |
| 48 | onChange={ onInputChange } |
| 49 | /> |
| 50 | |
| 51 | <input |
| 52 | type="email" |
| 53 | className="form-control mt-2" |
| 54 | placeholder="fernando@google.com" |
| 55 | name="email" |
| 56 | value={ email } |
| 57 | onChange={ onInputChange } |
| 58 | /> |
| 59 | |
| 60 | |
| 61 | { |
| 62 | (username === 'strider2' ) && <Message /> |
nothing calls this directly
no outgoing calls
no test coverage detected