Course contentsShow
← React
Lesson 1849 of 2,39643. RoutingFree lesson

Form Component: Progressive Enhancement

Using React Router's Form component to submit to actions with or without JavaScript.

Form Component: Progressive Enhancement

You'll learn how React Router's Form component enables your forms to work both with and without JavaScript, gracefully degrading for better user experience.

The Progressive Enhancement Pattern

When you use a regular HTML <form> element with React Router actions, it works perfectly fine without JavaScript — just like a traditional web form. The browser handles submission as a full page reload. But when JavaScript loads, React Router intercepts the submission and handles it client-side for a smoother experience.

The Form component from React Router makes this explicit. It looks and acts like a normal <form>, but automatically upgrades to a client-side navigation when JavaScript is available.

Basic Usage

import { Form } from 'react-router-dom';

function ContactForm() {
  return (
    <Form method="post" action="/contacts">
      <input type="text" name="name" />
      <input type="email" name="email" />
      <button type="submit">Send</button>
    </Form>
  );
}

Without JavaScript: This submits to your action as a regular POST request with a full page reload.

With JavaScript: React Router intercepts the submission, calls your action function, and updates the UI without reloading.

Think of It Like Stairs and an Elevator

Regular forms are the stairs — they always work. The Form component is like adding an elevator: when it's operational (JavaScript loaded), users get a faster, smoother ride. When it's not, the stairs still get them where they need to go.

This pattern ensures your app remains functional even if JavaScript fails to load, times out, or is disabled — critical for accessibility and resilience.

Key Takeaway: React Router's Form component provides progressive enhancement by working as a standard form submission without JavaScript and upgrading to client-side navigation when JavaScript is available.