| 3 | |
| 4 | |
| 5 | export const FormWithCustomHook = () => { |
| 6 | |
| 7 | const { formState, onInputChange, onResetForm, username, email, password } = useForm({ |
| 8 | username: '', |
| 9 | email: '', |
| 10 | password: '' |
| 11 | }); |
| 12 | |
| 13 | // const { username, email, password } = formState; |
| 14 | |
| 15 | |
| 16 | return ( |
| 17 | <> |
| 18 | <h1>Formulario con custom Hook</h1> |
| 19 | <hr /> |
| 20 | |
| 21 | <input |
| 22 | type="text" |
| 23 | className="form-control" |
| 24 | placeholder="Username" |
| 25 | name="username" |
| 26 | value={ username } |
| 27 | onChange={ onInputChange } |
| 28 | /> |
| 29 | |
| 30 | <input |
| 31 | type="email" |
| 32 | className="form-control mt-2" |
| 33 | placeholder="fernando@google.com" |
| 34 | name="email" |
| 35 | value={ email } |
| 36 | onChange={ onInputChange } |
| 37 | /> |
| 38 | |
| 39 | <input |
| 40 | type="password" |
| 41 | className="form-control mt-2" |
| 42 | placeholder="Contraseña" |
| 43 | name="password" |
| 44 | value={ password } |
| 45 | onChange={ onInputChange } |
| 46 | /> |
| 47 | |
| 48 | |
| 49 | <button onClick={ onResetForm } className="btn btn-primary mt-2">Borrar</button> |
| 50 | |
| 51 | </> |
| 52 | ) |
| 53 | } |