Open thomaswolff opened 5 years ago
I guess there is nothing wrong with your code, if think I already had an issue with different prop - I passed it and IntlTelInput
didn't seem to update. Luckily there is something you can do on your side:
<IntlTelInput
key={this.state.language}
countriesData={countriesData}
utilsScript={"libphonenumber.js"}
preferredCountries={["no"]}
separateDialCode={true}
/>
Just pass in key
prop (it's a special React prop for every component) that will change every time time the language changes. Preferably let it be unique, but for now passing this.state.language
should do just fine. When key
prop changes React knows to rerender the component.
I guess there is nothing wrong with your code, if think I already had an issue with different prop - I passed it and
IntlTelInput
didn't seem to update. Luckily there is something you can do on your side:<IntlTelInput key={this.state.language} countriesData={countriesData} utilsScript={"libphonenumber.js"} preferredCountries={["no"]} separateDialCode={true} />
Just pass in
key
prop (it's a special React prop for every component) that will change every time time the language changes. Preferably let it be unique, but for now passingthis.state.language
should do just fine. Whenkey
prop changes React knows to rerender the component.
@tomegz Setting the key
prop did indeed force the component to rerender, and the items in the dropdown list were updated. Thanks for the tip!
It would still be great if IntlTelInput
would rerender if the object passed to the countriesData
prop changed.
@thomaswolff this is true. Some other props sadly share the same behaviour
I guess there is nothing wrong with your code, if think I already had an issue with different prop - I passed it and
IntlTelInput
didn't seem to update. Luckily there is something you can do on your side:<IntlTelInput key={this.state.language} countriesData={countriesData} utilsScript={"libphonenumber.js"} preferredCountries={["no"]} separateDialCode={true} />
Just pass in
key
prop (it's a special React prop for every component) that will change every time time the language changes. Preferably let it be unique, but for now passingthis.state.language
should do just fine. Whenkey
prop changes React knows to rerender the component.
Thanks! I finally get it to work passing the changing value to key
!
Remember that this is just a hack to get around libraries' limitations. It'd be best if the issue was fixed in the library itself
Hi,
I'm using the
IntlTelInput
component in my project which supports two languages: English and Norwegian.countriesData
which is displayed in theFlagDropDown
component:countriesData-en
andcountriesData-nb
.language
state in my component.countriesData
prop for theIntlTelInput
according to the chosen language.I can see in the React Chrome Extension that the
countriesData
prop is updated inIntlTelInput
. However, the items in theFlagDropDown
component are not updated.In the screenshot below, you can see the
FlagDropDown
and the first entry in theCountriesData
prop when English is the selected language in my app. So far so good. These values match.When changing language to Norwegian, the
countriesData
prop is updated (as seen in the screenshot below). However, the items in theFlagDropDown
component are not updated.Excerpts from my code Imports of resource files
countriesData-en
andcountriesData-nb
.countriesData-en
is just a copy ofdefaultCountriesData
inAllCountries.js
, whereascountriesData-nb
has Norwegian translations for the country names.My component's render function
Any help on this matter would be much appreciated!