Created
July 21, 2025 07:35
-
-
Save AlexGeb/c54b092e17b57421a8f2db3d7a23d87a to your computer and use it in GitHub Desktop.
Hook that logs the render count of the component where it is used
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useEffect, useRef } from "react"; | |
| export const useRenderCount = (label: string) => { | |
| const count = useRef(0); | |
| useEffect(() => { | |
| count.current += 1; | |
| // eslint-disable-next-line no-console | |
| console.log(`${label} render count:`, count.current); | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment