const deleteDashHandler = useCallback((e) => {
if(e.which === 8 && applyCounselForm.phoneNumber.charAt(applyCounselForm.phoneNumber.length -1) === '-'){
e.preventDefault();
setApplyCounselForm(prev => ({
...prev,
phoneNumber: prev.phoneNumber.slice(0,prev.phoneNumber.length -2)
}))
return;
};
},[applyCounselForm.phoneNumber, setApplyCounselForm])
useEffect(() => {
if(applyCounselForm.phoneNumber.length === 3 && applyCounselForm.phoneNumber.charAt(applyCounselForm.phoneNumber.length -1) !== '-'){
setApplyCounselForm(prev => ({
...prev,
phoneNumber: prev.phoneNumber += '-'
}))
}else if(applyCounselForm.phoneNumber.length === 8 && applyCounselForm.phoneNumber.charAt(applyCounselForm.phoneNumber.length -1) !== '-') {
setApplyCounselForm(prev => ({
...prev,
phoneNumber: prev.phoneNumber += '-'
}))
}
},[applyCounselForm.phoneNumber, setApplyCounselForm])
...
<PhoneInput name="phoneNumber" value={applyCounselForm.phoneNumber || ''} onChange={applyCounselFormHandler} onKeyDown={deleteDashHandler} type="tel" inputMode="numeric"/>
...