|
| 1 | +import React, { useState } from 'react' |
| 2 | +import { useTitle, useFavicon, useForm } from '@brightleaf/react-hooks' |
| 3 | +export default () => { |
| 4 | + useTitle('useForm example from @brightleaf/react-hooks') |
| 5 | + const [formValues, setFormValues] = useState() |
| 6 | + const { addToForm, onSubmit } = useForm() |
| 7 | + |
| 8 | + return ( |
| 9 | + <div className="App content"> |
| 10 | + <pre>{formValues}</pre> |
| 11 | + <form |
| 12 | + onSubmit={onSubmit(data => { |
| 13 | + console.info('onsubmit handler', data) |
| 14 | + setFormValues(JSON.stringify(data, null, 2)) |
| 15 | + })} |
| 16 | + > |
| 17 | + <fieldset> |
| 18 | + <legend>Form Hook</legend> |
| 19 | + <input |
| 20 | + name="firstName" |
| 21 | + type="text" |
| 22 | + ref={addToForm} |
| 23 | + defaultValue="Kevin" |
| 24 | + /> |
| 25 | + <input |
| 26 | + name="lastName" |
| 27 | + type="text" |
| 28 | + ref={addToForm} |
| 29 | + defaultValue="Isom" |
| 30 | + /> |
| 31 | + <br /> |
| 32 | + <select ref={addToForm} name="dropdown" defaultValue="13"> |
| 33 | + <optgroup label="First Group"> |
| 34 | + <option value="1">First</option> |
| 35 | + <option value="2">Second</option> |
| 36 | + <option value="3">Third</option> |
| 37 | + </optgroup> |
| 38 | + <optgroup label="Second Group"> |
| 39 | + <option value="11">Second First</option> |
| 40 | + <option value="12">Second Second</option> |
| 41 | + <option value="13">Second Third</option> |
| 42 | + </optgroup> |
| 43 | + <optgroup label="Third Group"> |
| 44 | + <option value="21">Third First</option> |
| 45 | + <option value="22">Third Second</option> |
| 46 | + <option value="23">Third Third</option> |
| 47 | + </optgroup> |
| 48 | + </select> |
| 49 | + <br /> |
| 50 | + <input type="checkbox" name="check" defaultChecked ref={addToForm} /> |
| 51 | + <br /> |
| 52 | + <div> |
| 53 | + <label>The Radio</label> |
| 54 | + <div> |
| 55 | + <label> First </label> |
| 56 | + <input name="rgroup" type="radio" value="first" ref={addToForm} /> |
| 57 | + </div> |
| 58 | + <div> |
| 59 | + <label> Second </label> |
| 60 | + <input |
| 61 | + name="rgroup" |
| 62 | + type="radio" |
| 63 | + value="second" |
| 64 | + ref={addToForm} |
| 65 | + /> |
| 66 | + </div> |
| 67 | + </div> |
| 68 | + <br /> |
| 69 | + <button type="submit">Submit</button> |
| 70 | + </fieldset> |
| 71 | + </form> |
| 72 | + </div> |
| 73 | + ) |
| 74 | +} |
0 commit comments