Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Feature: πŸš€ Add useRenderCount hook for tracking component render count #529

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

talhaibnmahmud
Copy link

This pull request introduces a new utility hook, useRenderCount, designed to provide developers with valuable insights into component rendering behavior. With a focus on simplicity, flexibility, and efficiency, this hook facilitates easy tracking of component render counts, aiding in performance optimization and debugging efforts.

Key Features:

  • Automated Component Name Detection: The useRenderCount hook automatically detects the name of the component where it is invoked. Leveraging the Error stack trace, it captures the component name dynamically, eliminating the need for manual configuration and simplifying usage.
  • Efficient Render Count Tracking: The hook efficiently tracks the number of renders for the associated component. By utilizing React's useRef and useEffect hooks, render counts are accurately incremented without causing unnecessary re-renders or performance overhead.
  • Conditional Logging: Logging behavior is intelligently controlled based on the environment. Render counts are logged only in development mode, ensuring that production logs remain clean and free from unnecessary noise. This approach enhances code maintainability and promotes best practices in logging management.
  • Optional Custom Component Names: For added flexibility, developers can optionally provide custom names for components when invoking the hook. This feature enables more descriptive logging messages, enhancing code readability and facilitating easier identification of components in complex applications.

Copy link

changeset-bot bot commented Mar 6, 2024

πŸ¦‹ Changeset detected

Latest commit: ea45d27

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
usehooks-ts Minor
www Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@talhaibnmahmud talhaibnmahmud changed the title feature: πŸš€ Add useRenderCount hook for tracking component render count ✨ Feature: πŸš€ Add useRenderCount hook for tracking component render count Mar 6, 2024
@talhaibnmahmud talhaibnmahmud changed the title ✨ Feature: πŸš€ Add useRenderCount hook for tracking component render count ✨ Feature: πŸš€ Add useRenderCount hook for tracking component render count Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant