Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rename the `country` prop to `defaultCountry`?

See original GitHub issue

I have an idea. 😃 I wonder if renaming the country prop to defaultCountry would make it clearer how the prop is used and prevent people from thinking they can directly control the selected country via the country prop.

It just occurred to me that the country portion of this component (in contrast to the phone value) behaves basically like an uncontrolled component. And since a default prefix is conventionally used for uncontrolled components, this might make its behavior more self-documenting.

Read, for example,

With an uncontrolled component, you often want React to specify the initial value, but leave subsequent updates uncontrolled. To handle this case, you can specify a defaultValue attribute instead of value.

Then maybe you wouldn’t have to keep explaining to people (see #165, #138) how the supplied country is only used (as a default value) if the internal country state is not already set/initialized based on the supplied phone number (which you can think of as overriding the default)…

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

TylerRickcommented, Sep 24, 2019

Thanks, @catamphetamine. I’m glad you at least appreciate the carefully constructed issues I submit, even if you can’t or won’t implement all the changes I suggest.

Personally I think you should make the change. But that’s easy for me to say. 😃

I understand it would be hard to introduce such a change after you have many users already using the current API. Still, there are ways to do so, if you ever change your mind. (Helpful deprecation warnings in current minor releases (2.4), and wait until you increment the major version number (3.0) to introduce the breaking change, changing the deprecation warning into a helpful error message.)

Still, it’s a long name,

With respect to you, it is not. It is only 2 letters longer than defaultValue would be. display​Initial​Value​As​Local​Number, on the other hand, is a long name, but it’s okay, because it’s clear (whereas a shorter name for the same prop would likely be ambiguous). Clarity is more important than short.

But I agree that some people might assume they could change it

Exactly. It would be a logical conclusion to arrive it. (See #165, #138)

Unless a prop name has a default prefix or contain the word “initial”, one should in general be able to safely assume that changing that prop gives you rather direct control over something.

and the component could even handle such change but I didn’t add such functionality intentionally to keep things simple.

I understand.

catamphetaminecommented, Jan 1, 2020

Released version 3.x that renamed country to defaultCountry, as you suggested.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Updating the Default 'Country/Region' Property Field Type ...
Updating the Default 'Country/Region' Property Field Type from Single-Line Text to Dropdown Select · Navigate to the 'edit property' sidebar in the property ......
Read more >
Default Country · hbb20/CountryCodePickerProject Wiki · GitHub
To set default country programmatically, use setDefaultCountryUsingNameCode() method. setDefaultCountryUsingNameCode() or ...
Read more >
Idea: Set / Change default country for map - Tableau Community
Idea: Possibility to change the default country for locations/geographic roles. Context: We are located in The Netherlands. All our data is 'local'.
Read more >
when changing country, then display state and city to place ...
Please help me to display default value on state and city after changing Country. step 1) select country. step 2) select State. step...
Read more >
Set Default Country Code for Phone Field - ManageEngine
Navigate to the Field Properties > Appearance section on the right. Click Choose country below Default country code.​. The Select Country Code pop-up...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found