Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cannot get dialCode of undefined #69

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,16 @@ export default class PhoneInput extends Component {
key: index,
image: Flags.get(country.iso2),
label: country.name,
dialCode: `+${country.dialCode}`,
dialCode: `+${(country && country.dialCode) || ''}`,
Copy link
Contributor

@jling90 jling90 Oct 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line change necessary? PhoneNumber.getCountryDataByCode returns an array of objects. If country is a null-type it's going to crash on the line above anyway.

iso2: country.iso2
}));
}

getCountryCode() {
const countryData = PhoneNumber.getCountryDataByCode(this.state.iso2);
if (!countryData) {
return '';
}
return countryData.dialCode;
}

Expand Down