Building useDebugLogger – A Custom React Hook to Log Component and Method Execution Time
Debugging React components can get tricky—especially when you’re trying to figure out how long something took or how many times a method was called. Wouldn’t it be great if we could add a simple hook to log: Component mount and unmount times Page reloads Method execution durations (with number of calls) That’s exactly what we’ll build today: a reusable custom hook called useDebugLogger that makes tracking execution time a breeze. What We’re Building We’re going to build a hook that: Logs how long a component takes to mount (in ms). Logs when a component is unmounted. Logs if the user reloads the page. Logs how long any function (or async method) takes to run and how many times it’s been called. It works like this: const { logMethodExecution } = useDebugLogger("Home"); const myMethod = logMethodExecution("myMethod", () => { // your logic here }); Let’s go step by step

Debugging React components can get tricky—especially when you’re trying to figure out how long something took or how many times a method was called. Wouldn’t it be great if we could add a simple hook to log:
- Component mount and unmount times
- Page reloads
- Method execution durations (with number of calls)
That’s exactly what we’ll build today: a reusable custom hook called useDebugLogger
that makes tracking execution time a breeze.
What We’re Building
We’re going to build a hook that:
- Logs how long a component takes to mount (in ms).
- Logs when a component is unmounted.
- Logs if the user reloads the page.
- Logs how long any function (or async method) takes to run and how many times it’s been called.
It works like this:
const { logMethodExecution } = useDebugLogger("Home");
const myMethod = logMethodExecution("myMethod", () => {
// your logic here
});
Let’s go step by step