Progressive Enhancement with Forms
You'll learn how to build forms that work even when JavaScript fails or hasn't loaded yet by pairing useActionState with server actions.
The Core Idea
Progressive enhancement means your app provides basic functionality without JavaScript, then adds enhanced interactions when JavaScript is available. With useActionState and server actions, forms can submit and process data on the server even if the client-side JavaScript bundle fails to load or is still downloading.
When you use useActionState with a server action (marked with "use server"), React can serialize the form submission as a standard HTTP POST. The browser's native form submission kicks in automatically when JavaScript isn't available. Your server action runs, processes the data, and returns updated state—no client-side code required.
How It Works
Without JavaScript, the form submits traditionally. The server action executes, updates state on the server, and the page reloads with new data. With JavaScript, useActionState intercepts the submission, executes the action without a full page reload, and updates the UI smoothly with the pending state visible during processing.
Think of it like an elevator: it has emergency stairs (server-side form POST) that always work, but also a faster, smoother elevator (client-side JavaScript enhancement) when power is on.
The Benefits
Your users on slow connections see a working form immediately—no waiting for JavaScript bundles. Users with JavaScript disabled or corporate environments blocking scripts can still use your app. You get resilience: if your JS fails to load due to network issues or CDN problems, core functionality survives.
Key Takeaway: useActionState paired with server actions enables forms that gracefully degrade to traditional POST submissions, ensuring functionality regardless of JavaScript availability—true progressive enhancement.