Course contentsShow
← React
Lesson 500 of 2,39614. Uncontrolled ComponentsFree lesson

defaultValue vs value: The Key Difference

Learn how defaultValue sets initial state only once, while value creates a controlled component that must be managed.

defaultValue vs value: The Key Difference

You'll learn the crucial distinction between defaultValue and value props on input elements — one sets state once, the other creates ongoing control.

When working with form inputs in React, you have two ways to set their content: defaultValue and value. These look similar but behave completely differently.

The Core Distinction

value creates a controlled component. React takes full ownership of the input's content. Whatever you pass to value is what appears in the input, always. If the user types and you don't update state via onChange, the input won't change — React enforces the value you provided.

defaultValue creates an uncontrolled component. It sets the initial content when the component first mounts, then React lets go. The browser's DOM takes over, and the user can type freely without React managing every keystroke. This is a "set it and forget it" approach.

The Analogy

Think of value like a puppet on strings — you control every movement. Think of defaultValue like winding up a toy and letting it go — you set the starting point, but it moves on its own after that.

When to Use Each

Use value when you need:

  • Live validation as the user types
  • Formatted input (auto-uppercasing, masking)
  • To reset or modify input programmatically after mount

Use defaultValue when you need:

  • Simple forms where you only read values on submit
  • Better performance (no re-renders per keystroke)
  • Pre-filled forms where users just need an initial starting point

Key Takeaway: value makes React continuously control the input (requires onChange), while defaultValue only sets the starting value once and lets the DOM handle updates.