Ismayil Niftaliyev
Ismayil Niftaliyev

Reputation: 396

ReactJS: Do we still need pure functional components after introduction of PureComponent?

I have red some articles that say a component that extends React's PureComponent class has better performance than pure functional components in recent versions of React. So if this is correct then are there any use case that pure functional components are good options to use? Meanwhile React team has announced that they will optimize functional components. So who is the winner stateless functional components or components that inherited from PureComponent?

Upvotes: 1

Views: 533

Answers (1)

Dave Newton
Dave Newton

Reputation: 160191

Depends on what you're using them for.

Stateless functions are always dirty, hence always re-render. PureComponents do a shallow comparison so may not need to re-render. However they always do a complete shallow comparison, which also may not be what you want.

It boils down to shouldComponentUpdate and whether or not the pre-written one in PureComponent is suitable for the component in question.

(Noting that I don't know what the current... ahem state of functional components is in React; some of this may have already been baked in.)

Upvotes: 3

Related Questions