import { ChangeEventHandler } from 'react'; import MAP_TO_VALUE_CONVERTER from './consts/MAP_TO_VALUE_CONVERTER'; const createInputOnChangeHandler = ({ postSet, preSet, set, setType = 'string' as TypeName, valueKey = 'value', }: CreateInputOnChangeHandlerOptions = {}): ChangeEventHandler => (event) => { const { target: { [valueKey]: value }, } = event; const postConvertValue = MAP_TO_VALUE_CONVERTER[setType]( value, ) as MapToInputType[TypeName]; preSet?.call(null, event); set?.call(null, postConvertValue); postSet?.call(null, event); }; export default createInputOnChangeHandler;