( initialForm = {} )
| 1 | import { useState } from 'react'; |
| 2 | |
| 3 | export const useForm = ( initialForm = {} ) => { |
| 4 | |
| 5 | const [ formState, setFormState ] = useState( initialForm ); |
| 6 | |
| 7 | const onInputChange = ({ target }) => { |
| 8 | const { name, value } = target; |
| 9 | setFormState({ |
| 10 | ...formState, |
| 11 | [ name ]: value |
| 12 | }); |
| 13 | } |
| 14 | |
| 15 | const onResetForm = () => { |
| 16 | setFormState( initialForm ); |
| 17 | } |
| 18 | |
| 19 | return { |
| 20 | ...formState, |
| 21 | formState, |
| 22 | onInputChange, |
| 23 | onResetForm, |
| 24 | } |
| 25 | } |
no outgoing calls
no test coverage detected