Debugging helper functions for understanding why React components are re-rendering.
yarn add --dev @oliasoft-open-source/why-render
Note: this package is for debugging/testing only, and should not be merged into production code
To use for class components:
import { whyRender } from '@oliasoft-open-source/why-render';
componentDidUpdate(prevProps, prevState) {
whyRender(prevProps, this.props, prevState, this.state);
}
To use for function components:
import { useWhyRender } from '@oliasoft-open-source/why-render';
const Component = (props) => {
useWhyRender(props);
}
import { explainDiffernces } from '@oliasoft-open-source/why-render';
explainDiffernces(previous, current);