r/reactjs • • 4h ago

Discussion Three small React habits that cut down my re-render bugs

I'm learning React while working full-time, building small projects after work, and these three small habits actually reduced the silly re-render bugs I kept hitting:

  1. Keep state as low as it can live. I used to lift every bit of form state up to the top component and then wonder why everything re-rendered. Moving it down into the component that actually uses it fixed most of it.

  2. Stop wrapping everything in useMemo. Early on I memoised every function and value I could find and the code just got harder to read. Now I only reach for it when I can actually see a slow re-render.

  3. Derive instead of storing a second copy. I used to keep a filtered list in its own state alongside the original list, and they'd drift apart. Computing the filtered list from the state directly means there's nothing to go out of sync.

None of this is advanced — it's just what stopped my own bugs. What small habit did you pick up early that saved you the most debugging time?

0 Upvotes

6 comments sorted by

2

u/Darex97 4h ago

Stable keys. Never the index, never something that can repeat. A duplicate key once got me stuck in a re-render loop and I lost half a day on it.

2

u/devuxer 4h ago edited 3h ago

Regarding 2, why not eliminate *all* useMemo and turn on React Compiler?

1

u/Important-Ostrich69 3h ago

literally lol

1

u/yabai90 3h ago

You can also add use callback, it should be automatic whenever needed

1

u/yabai90 3h ago

You don't need useMemo or use callback anymore to begin with. They are auto set with react compiler. Third point apply to programming in general not just react. It's a very important point.