React Performance Issues: Reference Equality Not Value Change

Most React performance problems don’t come from re-renders. They come from creating new identities every render. This is something I completely overlooked for years. --- Example 👇 const options = { headers: { Authorization: token } }; useEffect(() => { fetchData(options); }, [options]); Looks harmless. But this runs on every render. Why? Because "options" is a new object every time → new reference → dependency changes → effect runs again. --- Now imagine this in a real app: - API calls firing multiple times - WebSocket reconnecting randomly - Expensive logic running again and again All because of reference inequality, not value change. --- The fix is simple, but rarely discussed 👇 const options = useMemo(() => ({ headers: { Authorization: token } }), [token]); Now the reference is stable. The effect runs only when it should. --- This doesn’t just apply to objects: - Functions → recreated every render - Arrays → new reference every time - Inline props → can break memoization --- The deeper lesson: React doesn’t compare values. It compares references. --- Since I understood this, my debugging approach changed completely. Whenever something runs “unexpectedly”, I ask: 👉 “Did the reference change?” --- This is one of those small concepts… that silently causes big production issues. --- Curious — have you ever debugged something like this? #ReactJS #Frontend #JavaScript #WebDevelopment #Performance

To view or add a comment, sign in

Explore content categories