1๐
โ
Hi export your NestedComponent using React.memo then it will not be rendered when any state is changed in ContainerComponent. This is for Functional Component.
Here is the code
import React, {useState} from "react";
const NestedComponent = () => {
const {value, setValue, errors} = useState(0);
console.log('child');
return (
<div>
ContainerComponent
</div>
);
};
export default React.memo(NestedComponent);
For class component, you should extends your class from React.PureComponent instead of React.Component like..
class NestedComponent extends React.PureComponent{
render(){
...
}
}
๐คKhabir
Source:stackexchange.com