Elly
Elly

Reputation: 337

when you click on a button, call up a function and at the same time change the screen

hi everyone i'm just learning react native and i have a question. when I click on a button, can I call up a method and change the screen at the same time? If I have for example the following piece of code:

HomePage.js
export default class HomePage extends Component {
constructor(props){
    super(props); 
    this.state = {
      aa:""
}
}
function(){
this.setState({aa:"ok"})
console.log(this.state.aa)
}
render(){
    return(<View> 
              <Button onPress={ ()=>this.function();this.props.navigation.navigate('Menu')} 
                        title="DETAILE"  color="orange"/> 
 </View> >
)}
}

How can I call up a function and change the screen at the same time?

Upvotes: 0

Views: 150

Answers (1)

MehdiNasiriPoor
MehdiNasiriPoor

Reputation: 334

Button onPress={ ()=>{this.function(),this.props.navigation.navigate('Menu')}} 
                    title="DETAILE"  color="orange"/>

Upvotes: 1

Related Questions