- Published on
useRenderCount Hook React

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>
);
};