Optimize React State with URL and Server Data

You don't need as much React state as you think. Most developers reach for `useState` by default. But a lot of "state" is already living somewhere else — in the URL, in server responses, in the route itself. Deriving UI from those sources keeps your app simpler, more shareable, and easier to debug. Instead of this: const [tab, setTab] = useState('overview'); Try this: const tab = new URLSearchParams(location.search).get('tab') ?? 'overview'; Now the active tab survives a refresh, works with the back button, and can be shared via link — all for free. The same principle applies on the server side. Whether you're working with Node.js, a .NET API, or a C# backend, let the server be the source of truth. Fetch it, derive from it, don't duplicate it. Less state means fewer bugs, fewer re-renders, and less mental overhead. Where are you still using local state that could live in the URL or server data instead? #React #JavaScript #WebDevelopment #Frontend #DotNet #NodeJS

To view or add a comment, sign in

Explore content categories