import React , { FC , ReactElement , createContext } from 'react' ; interface iFormContext { onChange ( e , setState ) : any ; setValue ( name , value , setState ) : any ; } interface iProps { children : ReactElement ; initialValues ? : any ; } export const FormContext = createContext < iFormContext > ( { onChange : ( ) => null , setValue : ( ) => null } ) ; const FormProvider = ( { children } ) : ReactElement => { function onChange ( e , setState ) { const { target : { name , value } } = e ; if ( name ) { setState ( ( prevState ) => ( { ... prevState , [ name ] : value } ) ) ; } } function setValue ( name , value , setState ) { setState ( ( prevState ) => ( { ... prevState , [ name ] : value } ) ) ; } const context = { onChange , setValue } ; return < FormContext . Provider value = { context } > { children } < /FormContext.Provider>; } ; export default FormProvider ;