interface Props { /** * Function desc */ phone: string; } const useMaskPhone = (phone: Props) => { // const [phone, phoneSetter] = useState(initialValue); let x = phone .toString() .replace(/\D/g, '') .match(/(\d{0,3})(\d{0,3})(\d{0,4})/); if (x) { const phone = !x[2] ? x[1] : '(' + x[1] + ') ' + x[2] + (x[3] ? '-' + x[3] : ''); return phone; } else { return 'invalid phone number'; } }; export default useMaskPhone;