React, Node.js, MySQL… and the Bugs That Broke My Brain
Written By Masum Munghate

React, Node.js, MySQL… and the Bugs That Broke My Brain

One developer’s survival log and the battle scars I earned along the way.


“It’ll Just Be a Weekend Project…”

That’s what I told myself. A bit of React, a sprinkle of Node.js, and a twist of MySQL—ship it by Monday. Three months and too many coffees later, I was furiously googling:

“Can you use your own code?”

Here’s how I lost-and then (sort of) won-my war with some relentless bugs.


React.js Struggle #1: The Schizophrenic Sidebar

The Problem: I needed my app’s sidebar to switch between “Admin” and “User.” Sounds easy. My Redux store, however, had other ideas. Sometimes the sidebar switched, sometimes it sulked.

My Fix:

  • Created a userSlice in Redux to hold the role.
  • Stored the role everywhere: right after login and in localStorage (backup!).
  • Used useSelector in React to read the current role and conditionally display menu items.

Pro tip: Own your roles. Don’t let Redux mood swings win.


React.js Struggle #2: Spilled Props All Over the Place

The Problem: The more components I added, the more props spilled everywhere. The state was a puddle, leaking from parent to child, child to parent.

My Fix:

  • Paused. Drew the component tree.
  • Traced where data belonged (“the owner”).
  • Lifted the state only when absolutely necessary.

Map before code. Saves so much cleaning up later.


React.js Struggle #3: The State Lifting Migraine

The Problem: Lifted a little state? Suddenly, errors rained down. My app embraced chaos.

My Fix:

  • Always initialized state (useState([]), not undefined).
  • Guarded against passing undefined to any child components.

Initialize your states. Trust me, you’ll sleep better.


React.js Struggle #4: Refresh? What Refresh?

The Problem: Refresh the page? Poof! All user data vanished. Like my app had amnesia.

My Fix:

  • Stored critical data (like user info and auth) in localStorage or sessionStorage.
  • Loaded it back in using useEffect on mount.

Persistence isn’t just about code; it’s about keeping your app’s memory intact.


React.js Struggle #5: Private Routes (Or Not So Private…)

The Problem: Unauthenticated users could waltz right into protected pages.

My Fix:

  • Wrote a <PrivateRoute> wrapper that checks for a valid login token.
  • If not, user gets redirected straight to /login.

Keep your routes guarded. Uninvited guests can wreak havoc!


Node.js Struggle #1: Role-Based Access Confusion

The Problem: Role-based API permissions sounded easy—until they weren’t. My server played bouncer, wasn’t checking the list, and let everyone in.

My Fix:

  • Gave each user a role stored in their data.
  • Added a checkRole() function as custom middleware to gatekeep API routes.

Let your code enforce the rules. Don’t run the club yourself.


Node.js Struggle #2: Error Cascade

The Problem: One API error could take down the whole server, not just the endpoint.

My Fix:

  • Wrapped all async logic in try...catch.
  • Centralized an error-handling middleware so the server just kept on trucking.

Error handling isn’t optional. It’s your server’s insurance policy.


What These Bugs Taught Me

Every bug is just your code’s (sometimes screaming) cry for help. Stay calm. Debug on. There’s always a fix-even if it means a midnight stack overflow binge.


Over to You!

What’s your “this bug nearly broke me” story? Drop it in the comments—let’s commiserate and laugh about it together.        


To view or add a comment, sign in

More articles by CodebergIT - Technology Works ( Hiring & Tech Partner )

Others also viewed

Explore content categories