react native how to call multiple functions when onPress is clicked

前端 未结 5 1800
离开以前
离开以前 2021-02-05 05:35

I am trying to call multiple functions when I click onPress using TouchableOpacity

For example:

functionOne(){
// do something
         


        
5条回答
  •  难免孤独
    2021-02-05 06:20

    There are a few ways to achieve this. One option would be to define a function that calls functionOne and functionTwo, and pass that on your onPress handler like so:

    
    functionOne(){
    // do something
    }
    
    functionTwo(){
    // do something
    }
    
    functionCombined() {
        this.functionOne();
        this.functionTwo();
    }  
    
     this.functionCombined()}/>
    
    

    Alternatively, and more concisely, you could express functionCombined inline in your JSX like so:

    
    functionOne(){
    // do something
    }
    
    functionTwo(){
    // do someting
    }
    
     { this.functionOne(); this.functionTwo(); }
     }
    /> 
    
          
    

提交回复
热议问题