Skip to content

React Hook Form Controlled Component — Fix Third-Party UI

DodaTech Updated 2026-06-24 2 min read

In this fix, you'll learn how to integrate controlled components with React Hook Form. This matters for integrating MUI, Ant Design, and other libraries, and appears in form inputs with custom pickers and selects.

The Problem

The following code demonstrates the typical mistake:

// Using register on a controlled component — not supported
<TextField {...register('email')} />
// TextField renders but value doesn't update form state

The Fix

Here is the corrected version:

// Use Controller to bridge controlled components
<Controller
  name="email"
  control={control}
  render={({ field }) => (
    <TextField {...field} />
  )}
/>
// Controlled component works correctly with the form

Prevention

  • Use Controller for all third-party controlled components (MUI, Ant Design, React Select).
  • The render prop receives { field, fieldState, formState } — spread field onto your component.
  • Access field errors via fieldState.error inside Controller's render.
  • For custom controlled components, implement the field props interface.
  • Use useController hook for a more imperative API in custom components.

Common Mistakes with hook form controlled

  1. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  2. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  3. Using return to exit a function early instead of wrapping a pure value in the monad

These mistakes appear frequently in real-world REACT code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does register not work with controlled components?

register uses ref to connect to native DOM elements. Controlled components manage their own internal state and don't expose a DOM input ref. Controller bridges this by managing value/onChange directly.

What is the difference between Controller and useController?

Controller is a render-prop component. useController is a hook. Use Controller for simple JSX usage. Use useController when building reusable form field components.

How do I handle custom onChange with Controller?

Spread field first, then override onChange: render={({ field }) => <TextField {...field} onChange={(e) => { field.onChange(e); yourLogic(e); }} />}.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro