12 tips to help you debug your react application

1. Check chrome dev tools →console tab for errors and warning

React Nathan Krasney
3 min readDec 15, 2021

Your console must be clean from warnings and errors.

A warning can easily turn into an error

Clean console using chrome dev tools

2. Open react dev tools using chrome dev tools →components. check props, state, and context values

react dev tools — Components tab

Compare the state\props\context that you expect with what you have in the Component tab

3. Put code breakpoint using chrome dev tools →sources

Breakpoint in react component using chrome dev tools

Put a breakpoint and debug your code

4. Perform self-code review. In particular, try to isolate specific lines of code

Simply go over the code line by line and look for logical mistakes. Tty to make an intelligent guess which lines of code to look in

5. Add console.log when loops are involved

You might have a code that performs a loop. Putting a breakpoint, in this case, might not be suited because the bug might rise on loop 100,000. console.log is more appropriate in this case

6. Check chrome dev tools →network when you suspect the bug relates to HTTP

Clean network tab in chrome dev tools

Status 2X is your friend , look for it

7. Check chrome dev tools →elements when you suspect the bug relates to the DOM

Element tab in chrome dev tools

Compare the dom properties you expect with the one that actually appears in the elements tab

8. Comment out suspicious lines of code

A nasty bug may be hard to isolate. One common technique is to start commenting out lines of code. You can start to comment each time 50% of the code, and once the bug disappears you know which part of the code to focus on.

9. Restart the application

Some tools: vs code, creat-react-app, … sometimes just need a restart and everything starts to function well

10. On development, check if the application works on the default port 3000 or maybe another port is used e.g. 3001 (can happen on vite)

vite allows you to run on multiple terminals each on a different port starting from 3000. So keep an eye on this

vite development server running on port 3001

11. Ask a friend to perform a code review

Sometimes the problem is clear but you just don't see it, another pair of eyes might very well help

12. There is no point in following these steps if you are tired.

You have a bug but it's late, you want to fix the bug but your brain is simply too tired to think. If you continue you will most likely add more bugs, so just stop, go to sleep and start over in the morning

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

React Nathan Krasney
React Nathan Krasney

Written by React Nathan Krasney

25+ years developing software. Lead web instructor & mentor. Focused in last few years on React. Check more info in www.nathankrasney.com

No responses yet

Write a response