MCPcopy Create free account
hub / github.com/Klerith/react-hooks / useForm

Function useForm

src/hooks/useForm.js:3–25  ·  view source on GitHub ↗
( initialForm = {} )

Source from the content-addressed store, hash-verified

1import { useState } from 'react';
2
3export 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}

Callers 1

FormWithCustomHookFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected