import { useCallback } from 'react' import type { FieldInputProps } from 'react-final-form' export type Props = { input: FieldInputProps enableReset: boolean onResetClick?: (callback: (resetValue: string) => void) => void } const defaultOnResetClick = (callback: (resetValue: string) => void) => { callback('') } const useFormInputReset = ({ input, enableReset, onResetClick = defaultOnResetClick, }: Props): (() => void) | undefined => { const resetClickHandler = useCallback(() => { onResetClick!((resetValue: string) => { input.onChange(resetValue) }) }, [input, onResetClick]) if (!enableReset) { return } return resetClickHandler } export default useFormInputReset