Member-only story

10 common pitfalls a React Developer should avoid

Priyanka Rodz
5 min readJan 12, 2025

--

Photo by ThisisEngineering on Unsplash

React is a powerful library for building user interfaces, but even experienced developers can fall into common traps that lead to bugs, inefficiencies, or unreadable code. This could cost app performance. Avoiding these mistakes can help a beginner or experienced developer write cleaner, more performant, and maintainable React applications. Let’s get to the pitfalls and how to avoid them.

Overuse and neglected cleanup of useEffect hook:

Overusing useEffect can lead to unnecessary re-renders, while skipping useEffect cleanup can lead to memory leaks, especially in timers, subscriptions, or event listeners.

Solution:

  • Avoid overuse: Avoid using useEffect for calculations or updating state derived from props. Use useMemo or inline calculations instead. Use useEffect strictly for side effects like API calls, subscriptions, or DOM manipulations.
  • Cleanup: Clear any timers, unsubscribe listeners or subscriptions inside the cleanup function returned in useEffect.
// Bad code - Misuse of useEffect for derived state
useEffect(() => {
setFilteredData(list.filter(item => item.active));
}, [list]);

---------------------------------------------------------------------------

// Good code
const data = useMemo(() =>…

--

--

Priyanka Rodz
Priyanka Rodz

Written by Priyanka Rodz

Technical Writer | Avid Reader | Emcee script writer

No responses yet