thegamenicorus / react-native-phone-input

Phone input box for React Native
https://www.npmjs.com/package/react-native-phone-input
MIT License
395 stars 449 forks source link

TypError: undefined is not an object (evaluating 'this.countryPicker.openModal') #138

Open meliodev opened 4 years ago

meliodev commented 4 years ago

When I invoke onPressFlag(){ this.countryPicker.openModal() } by pressing the country flag, I get undefined. Here is the code below:

`import React, { Component } from 'react'; import { StyleSheet, View } from 'react-native';

import PhoneInput from 'react-native-phone-input'; import CountryPicker from 'react-native-country-picker-modal';

export default class Test4 extends React.Component { constructor() { super();

this.onPressFlag = this.onPressFlag.bind(this);
this.selectCountry = this.selectCountry.bind(this);
this.state = {
  cca2: 'US',
};

}

componentDidMount() { this.setState({ pickerData: this.phone.getPickerData(), }); }

onPressFlag(){ this.countryPicker.openModal() }

selectCountry(country){ this.phone.selectCountry(country.cca2.toLowerCase()) this.setState({cca2: country.cca2}) }

render(){ return(

{ this.phone = ref; }} onPressFlag={this.onPressFlag} /> { this.countryPicker = ref; }} onChange={(value)=> this.selectCountry(value)} translation='eng' cca2={this.state.cca2} >
)

} }

let styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', padding: 20, paddingTop: 60, }, });`

saidhappy010 commented 4 years ago

I have the same issue. please, anyone has the solution?. thanks.

daviedgie commented 4 years ago

Please refer to this my friend. https://github.com/xcarpentier/react-native-country-picker-modal/issues/270#issuecomment-569040444

sargamverma commented 4 years ago

I have the same issue. I am using this with expo application . Please anyone help. Its urgent.

Thanks in andvance