xcarpentier / react-native-country-picker-modal

🇦🇶 Country picker provides a modal allowing a user to select a country from a list. It display a flag next to each country name.
https://reactnative.gallery/xcarpentier/country-picker
MIT License
1.08k stars 802 forks source link

[prod build only] Object is null or undefined #118

Closed akiradeveloper closed 5 years ago

akiradeveloper commented 6 years ago

screenshot_20180518-205711

This error arises once I changed from android:dev to android:prod. The RN version is 0.46.0 and library version is 0.5.1

My guess is that transpiler works badly; the calling of from method tells us that the pointed code isn't safe for the transpiler.

  static renderImageFlag(cca2, imageStyle) {
    return cca2 !== '' ? (
      <Image
        style={[styles.imgStyle, imageStyle]}
        source={{ uri: countries[cca2].flag }} // this is L112
akiradeveloper commented 6 years ago

Oh sorry, that was master branch's

the L112 (of v.0.5.1) is actually the line below (https://github.com/xcarpentier/react-native-country-picker-modal/blob/v0.5.1/src/CountryPicker.js)


  static renderFlag(cca2, itemStyle, emojiStyle, imageStyle) {
    return (
      <View style={[styles.itemCountryFlag, itemStyle]}>
        {isEmojiable
          ? CountryPicker.renderEmojiFlag(cca2, emojiStyle)
          : CountryPicker.renderImageFlag(cca2, imageStyle)}
      </View>
    )
  }

  constructor(props) {
    super(props)
    this.openModal = this.openModal.bind(this)

    let countryList = [...props.countryList] // L112
    const excludeCountries = [...props.excludeCountries]
akiradeveloper commented 6 years ago

I found that props.countryList is undefined

akiradeveloper commented 6 years ago

I think the cause is defaultProps is somewhat ignored

VadSiam commented 6 years ago

@akiradeveloper you right. I got this error too on my Android. And I was found and solve problem : <CountryPicker cca2={cca2.toUpperCase()} {...props} />

cca2 need to be in upper case. It help me

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.