Rename the `country` prop to `defaultCountry`?
See original GitHub issueI 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, https://reactjs.org/docs/uncontrolled-components.html#default-values:
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 ofvalue
.
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:
- Created 4 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top GitHub Comments
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.)
With respect to you, it is not. It is only 2 letters longer than
defaultValue
would be.displayInitialValueAsLocalNumber
, 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.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.I understand.
Released version
3.x
that renamedcountry
todefaultCountry
, as you suggested.