Calling a function in React

前端 未结 6 1965
感动是毒
感动是毒 2021-02-04 21:55

I\'m a beginner in React, and I\'m a little confused about calling a function in React.

I saw the following ways and I don\'t know when to use each and which one.

<
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-04 22:47

    In ES6 you can use normal function or Arrow Function:

    Function1 (Normal Function)

    functionA(){
       //Something here
    }
    

    Then should call this.functionA()

    Function2 (ArrowFunction)

    functionA = () => {
       //SomeThing Here
    }
    

    Then should call this.functionA

    *Function3 (Eg: in a const of React) *

    const A = (functionTest) =>{
      return (
         
    {functionTest}
    ); }

    functionTest is mapStateToProps in React :)

    I hope it is helpful for you :)

提交回复
热议问题