Pure component added to index of react component (#34141)
* Pure component * SPG changes
This commit is contained in:
committed by
Aman Mittal
parent
f776235ddf
commit
af9db2657b
@ -82,6 +82,28 @@ const Cat = props =>
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Pure Components
|
||||||
|
|
||||||
|
This type of component was added in React 16 and can be used to declare stateless non-functional components.
|
||||||
|
These components work like normal stateful components (class-based component) but with `shouldComponentUpdate()` pre-defined.
|
||||||
|
They are the fastest components and make the render cycle much cleaner and leaner.
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
class Cat extends React.PureComponent {
|
||||||
|
render() {
|
||||||
|
return(
|
||||||
|
<div>
|
||||||
|
<h1>{this.props.name}</h1>
|
||||||
|
<p>{props.color}</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
This component will only render if there is a change in its props; not when the parent re-renders.
|
||||||
|
|
||||||
### More Information:
|
### More Information:
|
||||||
|
|
||||||
[https://reactjs.org/docs/components-and-props.html](Components and Props)
|
[https://reactjs.org/docs/components-and-props.html](Components and Props)
|
Reference in New Issue
Block a user