this.state = {
phone: ''
};
I want to find the length of the phone variable in state on change so that if the length is 10 I can perform an action.
Also if possible can you let me know how can enable and disable native-base button programmatically in react native.
I'm a beginner in react native
If the phone number is saved as a string then it is very easy. You can just do
let phoneNumberLength = this.state.phone.length
Then you can use it in an if statement
if (phoneNumberLength === 10) {
// do something here
}
The Button component in nativebase has a disabled prop that you can use. http://docs.nativebase.io/Components.html#button-disabled-headref
You could set a value in your state to control whether the button is disabled or not. Calling this.state({buttonDisabled: true})
will disable the button
this.state {
buttonDisabled: false
}
<Button disabled={this.state.buttonDisabled} />
If the phone number is saved as a string then it is very easy. You can just do
let phoneNumberLength = this.state.phone.length
Then you can use it in an if statement
if (phoneNumberLength === 10) {
// do something here
}
The Button component in nativebase has a disabled prop that you can use. http://docs.nativebase.io/Components.html#button-disabled-headref
You could set a value in your state to control whether the button is disabled or not. Calling this.state({buttonDisabled: true})
will disable the button
this.state {
buttonDisabled: false
}
<Button disabled={this.state.buttonDisabled} />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With