Docs
Render Info

Render Info

Debug renders and improve performance

About

The useRenderInfo hook tracks and logs rendering information in a component. It keeps track of the number of renders, the time elapsed since the last render, and the timestamp of the current render. This hook is particularly helpful during development, providing insights into the rendering behavior of a component for performance optimization and issue identification.

Return Values

NameTypeDescription
infoobjectAn object containing information about the component’s rendering.
info.namestringThe name of the component.
info.rendersnumberThe number of times the component has rendered.
info.sinceLastRendernumberThe time elapsed in milliseconds since the last render.
info.timestampnumberThe timestamp of the current render.

Installation

Run the following command:

npx scriptkavi-hooks@latest add render-info

Usage

import { useRenderInfo } from "@/hooks/render-info"
import * as React from "react"
 
export default function App() {
  const info = useRenderInfo("App")
 
  const [count, setCount] = React.useState(0)
 
  return (
    <section>
      <h1>useRenderInfo</h1>
      <button className="primary" onClick={() => setCount(count + 1)}>
        Re-Render
      </button>
      <table>
        <thead>
          <tr>
            <th colSpan={2}>Render Info</th>
          </tr>
        </thead>
        <tbody>
          {Object.keys(info).map((key) => {
            return (
              <tr key={key}>
                <th>{key}</th>
                <td>{info[key]}</td>
              </tr>
            )
          })}
        </tbody>
      </table>
    </section>
  )
}