#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
Debugging Techniques (React)

Code Flow and Warnings

Understanding code flow in React means knowing the order in which your components render, update the DOM and run effects. Warnings are the yellow messages React prints in the browser console during development, pointing out code that works for now but is likely to cause bugs. Reading both helps you debug problems that do not crash the app but still make it behave strangely.

The order things happen in

When state or props change, React follows the same steps every time:

  1. Render: React calls your component function to get new JSX. This should be pure, with no side effects.
  2. Commit: React compares the new output with the previous one and updates only the DOM nodes that changed.
  3. Effects: after the browser paints, React runs useEffect callbacks whose dependencies changed. Before re-running an effect, it runs the previous effect's cleanup function.

Parents render before children, but child effects run before parent effects. Adding a console.log at the top of a component and inside its effect quickly shows you this order and how often each part runs.

function Profile({ userId }) {
  console.log('render Profile', userId);

  useEffect(() => {
    console.log('effect: load user', userId);
    return () => console.log('cleanup for', userId);
  }, [userId]);

  return <h2>User {userId}</h2>;
}

Why logs appear twice in development

If your app is wrapped in <StrictMode>, React deliberately renders components twice and mounts, unmounts and remounts effects once in development. The goal is to expose code that is not pure or effects that are missing cleanup. This does not happen in production builds. Seeing double logs is expected, not a bug in your code, though recent React versions dim the second log in the console.

Warnings you will meet early

Warning (shortened)What it means
Each child in a list should have a unique "key" propItems from map() need a stable key, such as a database id.
A component is changing an uncontrolled input to be controlledThe input's value started as undefined and later became a string. Initialise state with ''.
You provided a `value` prop without an `onChange` handlerThe field is read-only. Add onChange or use defaultValue.
Cannot update a component while rendering a different componentA state setter is being called during render. Move it into an event handler or effect.
React Hook useEffect has a missing dependencyAn ESLint rule spotted a variable used inside the effect but not listed in its dependency array.

Clicking the small arrow next to a warning in the console expands a component stack, which lists the component tree leading to the problem. Read it from the top to find the file to fix.

The mistake: ignoring yellow text

Because warnings do not stop the app, it is tempting to scroll past them. But each one usually predicts a real bug. A missing key can make a list show the wrong item's state after reordering. A missing effect dependency means the effect keeps using stale values. Silencing the dependency rule with a comment instead of fixing the code is a common source of hard-to-find bugs. Treat a clean console as part of finishing a feature.

Using an array index as the key is another trap. It removes the warning, but if items can be inserted, removed or reordered, React will still mix up their state. Prefer a stable id from the data.

Takeaways

  • Render, commit, then effects: keep render pure and put side effects in effects or handlers.
  • Double logs in development come from StrictMode and are intentional.
  • Read each warning and its component stack, and fix the cause rather than hiding it.

Ready to master real-world web development?

Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.

Explore Course