import React from "react" ; description export param { * } initialValue param { string } key returns export function useForm ( initialValue , key ? ) { if ( ! ! key ) initialValue = { [ key ] : initialValue } ; const [ form , setForm ] = React . useState ( initialValue ) ; React . useEffect ( ( ) => { console . log ( form ) ; } , [ form ] ) ; const telValidation = ( telNumber ) => { const reg = /([0-1]{3})-([0-9]{3,4})-([0-9]{4})/gm ; const faultReg = /([0-1]{3})([0-9]{4})([0-9]{4})/gm ; if ( reg . test ( telNumber ) ) { return telNumber ; } else { const result = telNumber . replace ( faultReg , `$1-$2-$3` ) ; return result ; } } ; const onChange = ( e ) => { let { name , value } = e . target ; value = name === "telNumber" ? telValidation ( value ) : value ; setForm ( { ... form , [ name ] : value , } ) ; } ; const obj = { onChange , } ; if ( ! key ) obj [ "form" ] = form ; else obj [ key ] = form [ key ] ; return obj ; }