0
I’m trying to use a if
thus:
<Button
iconRight={{
name: 'search',
type: 'font-awesome'
}}
title='BUSCAR'
buttonStyle={{
marginTop: 15,
borderRadius: 7,
backgroundColor:'#2C5CAA'
}}
onPress={(function() {if (this.state.busca.length > 0){
alert(this.state.busca.length);
}else{
this.props.navigation.navigate('Lista', {
busca: this.state.busca,
city: this.state.city })}
})
}
/>
However, I am getting an error in the variable this.state.busca
:
Undefined is not an Object (evaluating 'this.state.busca')
How to solve?
Sorry I didn’t enter the full code, it’s a button. I changed the question @wmsouza
– Italo Rodrigo
What is the content of
this.state.busca
the good thing would be you create a snack– Mateus
Probably the context of
this
is for the anonymity function within theonPress()
, you need to bind in the context of your class to be able to access thestate
of the component– Yago Azedias