react-phone-input-2
react-phone-input-2 copied to clipboard
Is it possible to re-render component based on localization?
Hi there,
I'm working on a localized dashboard, where user can change display language without refresh the page,
But it seems, that PhoneInput component takes initial value of localization and doesn't re-render if value changed,
I have created a wrapper component for PhoneInput, and tried to force re-render it via react memo, but for nothing.
Is there any possible way to do it?
Thanks in advance,
I'm not sure why it doesn't rerender, but for us we found two solutions:
- if you are wrapping the component then wrap the country prop in a useEffect
const [inputCountry, setInputCountry] = useState(propsCountry);
useEffect(() => {
if (propsCountry) setInputCountry(propsCountry);
}, [country]);
<PhoneInput
country={country}
- also you can try adding a key to the component to tell react to rerender
<PhoneInput
key={propsCountry}
country={propsCountry}