Codecademy Logo

React Forms

Related learning

  • In this React course, you’ll build powerful interactive applications with one of the most popular JavaScript libraries.
    • Intermediate.
      13 hours
  • Learn how to build advanced web applications with React and Redux.
    • Includes 6 Courses
    • With Certificate
    • Intermediate.
      22 hours

Controlled vs. Uncontrolled Form Fields

In React, form fields are considered either uncontrolled, meaning they maintain their own state, or controlled, meaning that a parent component maintains their state and passes it to them to display. Usually, the form fields will be controlled.

The example code shows an uncontrolled input and a controlled input.

const uncontrolledInput = <input />;
const controlledInput = (
<input value={stateValue} onChange={handleInputChange} />
);

Controlled Components

A controlled form element in React is built with a change handler function and a value attribute.

const controlledInput = (
<input value={stateValue} onChange={handleInputChange} />
);

Learn more on Codecademy

  • In this React course, you’ll build powerful interactive applications with one of the most popular JavaScript libraries.
    • Intermediate.
      13 hours
  • Learn how to build advanced web applications with React and Redux.
    • Includes 6 Courses
    • With Certificate
    • Intermediate.
      22 hours