Back to Blog
ReactFormsControlled ComponentsUncontrolled Components

React Controlled vs Uncontrolled Components

Understand the difference between controlled and uncontrolled components in React and when to use each.

B
Bootspring Team
Engineering
April 21, 2019
6 min read

Understanding when to use controlled versus uncontrolled components is essential for building React forms. Here's a comprehensive guide to both approaches.

Controlled Components#

Loading code block...

Uncontrolled Components#

Loading code block...

Controlled Form Example#

Loading code block...

Uncontrolled Form Example#

Loading code block...

File Inputs (Always Uncontrolled)#

Loading code block...

Hybrid Approach#

Loading code block...

Controlled Select#

Loading code block...

Controlled Checkbox#

Loading code block...

Controlled Radio Buttons#

Loading code block...

Formatting Input Values#

Loading code block...

Reset Form#

Loading code block...

Comparison Table#

Feature | Controlled | Uncontrolled -------------------------|-------------------|------------------ Value source | React state | DOM Re-renders on input | Yes | No Real-time validation | Easy | Manual Form submission | From state | From refs Initial value | value prop | defaultValue prop File inputs | Not supported | Supported Performance | More re-renders | Fewer re-renders Testing | Easier | Requires DOM

Best Practices#

Use Controlled When: ✓ Real-time validation needed ✓ Conditional field disabling ✓ Input formatting required ✓ Dynamic form modifications ✓ Multiple inputs depend on each other Use Uncontrolled When: ✓ Simple forms with minimal validation ✓ File inputs ✓ Performance is critical ✓ Integrating with non-React code ✓ One-time value reading General Tips: ✓ Stay consistent within a form ✓ Use controlled for complex interactions ✓ Consider form libraries for large forms ✓ defaultValue, not value, for uncontrolled

Conclusion#

Controlled components give you full control over form state through React, enabling real-time validation, formatting, and dynamic behavior. Uncontrolled components let the DOM handle state, offering better performance for simple forms. Choose controlled for interactive forms needing validation, and uncontrolled for simple forms or file inputs. For complex forms, consider using form libraries like React Hook Form that offer the best of both approaches.

Share this article

Help spread the word about Bootspring

Related articles