Javascript: A question about react stateless function

Created on 4 Jul 2016  路  4Comments  路  Source: airbnb/javascript

In the link
https://github.com/reactjs/redux/issues/1176

I found that stateless function is slow because of rendering, so they recommend React function even if it is stateless.

Is there any other reason you suggest stateless function?

question react

All 4 comments

State is toxic and adds cognitive overhead, and it should be avoided whenever possible. SFCs aren't better because they're faster - although in the future they _will_ be faster - they're better precisely because they're stateless.

In addition, "performance" should always be the last concern, prioritized far after maintainability, clarity/cleanliness, elegance, and after things are tested _and_ benchmarked. A style guide only recommends one option for performance when all options are otherwise equal - a rare occurrence.

If you're measuring an actual perf loss due to re-renders of functional components, you can wrap them with recompose's pure, onlyUpdateForKeys, or onlyUpdateForPropTypes.

@ljharb thanks a lot for your comment.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stephenkingsley picture stephenkingsley  路  3Comments

progre picture progre  路  3Comments

kozhevnikov picture kozhevnikov  路  3Comments

danielfttorres picture danielfttorres  路  3Comments

graingert picture graingert  路  3Comments