- Published on
useRenderCount Hook React
![useRenderCount Hook React](https://user-images.githubusercontent.com/33494971/269602373-9aa20fcb-72ca-49ca-902c-e5866a74bf0e.png)
useRenderCount Hook React
useRenderCount Code and Usage
useRenderCount is a hook to count the number of times a component renders.
import { useRef } from "react";
const useRenderCount = () => {
const renderCountRef = useRef(0);
renderCountRef.current += 1;
return renderCountRef.current;
};
// Usage
const RenderCountExample = () => {
const renderCount = useRenderCount();
return (
<div>
<p>Render count: {renderCount}</p>
</div>
);
};