Reputation: 323
What is the best between functionnal component and PureComponent when it's a stateless component ?
This :
import React from 'react';
export default function Example(props){
return (
<div>
{props.myProps}
</div>
)
}
Or this :
import React from 'react';
export default class Example extends React.PureComponent {
render() {
return(
<div>
{this.props.myProps}
</div>
)
}
}
Upvotes: 0
Views: 118
Reputation: 5669
When its a stateless component, and you are not using shouldComponentUpdate() or any lifecycle methods, then you should go with functional components as this will be light weight than PureComponents.
Upvotes: 1
Reputation: 443
Functional components are more of building blocks and easy to reason about and can be/should be composed to make more complex components. And as per React docs, they might be able to enhance the performance of Functional components in future.
Pure Component is just a regular component with a syntactic sugar around props check in case one needs to implement shouldComponentUpdate based on props check; with Pure components you get that by default.
Upvotes: 0