DEV Community

Hossain MD Athar
Hossain MD Athar

Posted on

Answer: How I can count how many times my component rendered in a react component

If you are working on a big project, create a custom hook. In this way, u can tackle unnecessary renders.

Creating Custom Hook for renderCount.

import { useRef, useEffect } from "react"
export default () => {
  const renderCount = useRef(0);
  useEffect(() => {
    renderCount.current++;
  });
  return renderCount.current;
};

then…

Top comments (0)