What is the difference between both button click in the given React Component?

后端 未结 3 1085
情书的邮戳
情书的邮戳 2020-11-30 14:50

Is there any difference between both the button click event in the given component? Which is the preferred way to write?

export default class App extends Com         


        
3条回答
  •  半阙折子戏
    2020-11-30 15:40

    From doc

    The problem with this syntax is that a different callback is created each time the Button renders. In most cases, this is fine. However, if this callback is passed as a prop to lower components, those components might do an extra re-rendering.

    We generally recommend binding in the constructor or using the class fields syntax, to avoid this sort of performance problem.

提交回复
热议问题