You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allows user to enter phone input using E.164 format.
Visual References
Description
I've built this component before using react-phone-number-input, however it does not fully support controlled behavior. This is taken from my previous code:
exportconstPhoneInputMobile=React.forwardRef<React.ElementRef<typeofReactPhoneInput>,Omit<React.ComponentPropsWithoutRef<typeofReactPhoneInput>,'country'|'value'|'onChange'>>(({ international =true, className, ...props},ref)=>{const{ country, value, onValueChange }=usePhoneInputContext();// https://github.com/catamphetamine/react-phone-number-input/blob/master/source/usePhoneDigits.js#L123// Underlying `usePhoneDigits` does not fully support controlled behavior, we needed this debounce hack to sync the value back to our store.consthandleChange=debounce((v: Value)=>onValueChange(v),50);return(<ReactPhoneInputref={ref}international={international}className={cn('px-3 py-2',className)}inputComponent={InputGroupInput}country={country}value={value}onChange={handleChange}{...props}/>);});PhoneInputMobile.displayName='PhoneInputMobile';
Ideally, I was looking for a headless library that can fully support controlled behavior. I found react-phone-number-input, and unfortunately they suffer the same problem.
Would require more thoughts on this as well as the API design.
Phone Input
Allows user to enter phone input using E.164 format.
Visual References
Description
I've built this component before using
react-phone-number-input
, however it does not fully support controlled behavior. This is taken from my previous code:Ideally, I was looking for a headless library that can fully support controlled behavior. I found
react-phone-number-input
, and unfortunately they suffer the same problem.Would require more thoughts on this as well as the API design.
Anatomy
Libraries / Hooks
usePhoneInput
Hook ybrusentsov/react-international-phone#215 for more details.Credits
Visual reference taken from Shadcn Phone Input.
The text was updated successfully, but these errors were encountered: