useRenderCount
Returns the number of renders of a component.
Installation
npx rabbithook@latest add use-render-count
Usage
import useRenderCount from "@/hooks/use-render-count";
function Component() { const renderCount = useRenderCount();
return ( <p>Component rendered { renderCount } times</p> );}
Code
import { useEffect, useRef } from "react";
function useRenderCount(): number { const count = useRef<number>(1);
useEffect(() => { count.current++; });
return count.current;}
export default useRenderCount;
import { useEffect, useRef } from "react";
function useRenderCount() { const count = useRef(1);
useEffect(() => { count.current++; });
return count.current;}
export default useRenderCount;