Why shouldn't JSX props use arrow functions or bind?

前端 未结 6 1343
孤独总比滥情好
孤独总比滥情好 2020-11-22 13:07

I\'m running lint with my React app, and I receive this error:

error    JSX props should not use arrow functions        react/jsx-no-bind

A

6条回答
  •  迷失自我
    2020-11-22 13:23

    Using inline functions like this is perfectly fine. The linting rule is outdated.

    This rule is from a time when arrow functions were not as common and people used .bind(this), which used to be slow. The performance issue has been fixed in Chrome 49.

    Do pay attention that you do not pass inline functions as props to a child component.

    Ryan Florence, the author of React Router, has written a great piece about this:

    https://cdb.reacttraining.com/react-inline-functions-and-performance-bdff784f5578

提交回复
热议问题