Skip to content

How to Fix useEffect Debug Logging

DodaTech Updated 2026-06-26 1 min read

The Problem

In this quick-fix, you'll learn how to properly debug useEffect with console.log. This matters because debug logging is essential but confusing without structure. In real-world applications, this pattern appears in tracking effect order debugging dependency issues.

The Wrong Way

function Debug({ userId }) {
  console.log('Render:', userId);
  useEffect(() => { console.log('Effect:', userId); return () => console.log('Cleanup:', userId); });
  return <div>{userId}</div>;
}
Hard to tell if cleanup ran between renders

The Right Way

function Debug({ userId }) {
  console.log('[Render] userId:', userId);
  useEffect(() => {
    console.log('[Effect:fetch] Starting fetch for:', userId);
    return () => { console.log('[Effect:fetch] Cleanup for:', userId); };
  }, [userId]);
  return <div>{userId}</div>;
}
Clear labeled output showing lifecycle order

Prevention

  • Label console.log with component and effect names in brackets
  • Log in render effect and cleanup to see full lifecycle
  • Use React DevTools Profiler for visual debugging
  • Remove debug logs before deploying

FAQ

### Why does log appear twice in StrictMode??

StrictMode intentionally double-invokes effects in development. Each effect runs then cleanup then effect runs again. Production logs appear once.

How to see which props changed between renders??

Store previous props in ref and compare: const prev = useRef(); useEffect(() => { console.log('Changed from', prev.current, 'to', value); prev.current = value; }, [value]);

Can I use React DevTools without console.log??

Yes Profiler shows renders and causes. Components tab to inspect props and state at any point.

This guide is brought to you by DodaTech -- built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro