---
title: "How do I handle many form inputs with one change handler in React?"
description: "Give each input a name, keep the values in one state object, and update the matching key in a single handler. Covers checkboxes, numbers, TypeScript and when to skip state entirely."
url: https://www.danny.engineering/answer/react/how-do-i-handle-many-form-inputs-with-one-change-handler-in-react
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T18:57:00.000Z
tags: ["React"]
---

# How do I handle many form inputs with one change handler in React?

## The short answer


Store the form in one state object, give each input a `name` that matches a key, and use a computed property name in a single handler to update that key. Copy the previous state rather than changing it.


```typescript
const [form, setForm] = useState({ name: '', email: '', role: 'dev' });

function handleChange(event: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>) {
  const { name, value } = event.target;
  setForm((prev) => ({ ...prev, [name]: value }));
}

<input name="name" value={form.name} onChange={handleChange} />
<input name="email" value={form.email} onChange={handleChange} />
```


## Why it happens


With controlled inputs, each field needs a value in state and a way to update it. Writing a separate `useState` and handler for every field works for two inputs, but a form with ten fields turns into a wall of almost identical code.


The change event already tells you which input changed, through `event.target.name`. If your state keys match the input names, one function can update any field. The square brackets in `[name]: value` are a JavaScript computed property name: they use the value of the variable `name` as the key.


You must spread the previous state because React replaces state with whatever you pass. Returning only the changed field would wipe the others.


## How to fix it


### One handler with computed keys


This is the version above, typed so TypeScript checks the keys too.


```typescript
type Signup = { name: string; email: string; role: string };

function SignupForm() {
  const [form, setForm] = useState<Signup>({ name: '', email: '', role: 'dev' });

  function handleChange(
    event: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>,
  ) {
    const { name, value } = event.target;
    setForm((prev) => ({ ...prev, [name as keyof Signup]: value }));
  }

  return (
    <form>
      <input name="name" value={form.name} onChange={handleChange} />
      <input name="email" type="email" value={form.email} onChange={handleChange} />
      <select name="role" value={form.role} onChange={handleChange}>
        <option value="dev">Developer</option>
        <option value="design">Designer</option>
      </select>
    </form>
  );
}
```


### Handle checkboxes and numbers


Checkboxes report their state in `checked`, not `value`, and every input's `value` is a string. Branch on the input type.


```typescript
function handleChange(event: React.ChangeEvent<HTMLInputElement>) {
  const { name, type, value, checked } = event.target;

  setForm((prev) => ({
    ...prev,
    [name]: type === 'checkbox' ? checked : type === 'number' ? value === '' ? '' : Number(value) : value,
  }));
}

<input type="checkbox" name="newsletter" checked={form.newsletter} onChange={handleChange} />
<input type="number" name="age" value={form.age} onChange={handleChange} />
```


Keeping an empty number field as an empty string lets the user clear it; converting straight to `Number('')` would turn it into 0.


### Use useReducer for larger forms


When updates need validation or several fields change together, a reducer keeps that logic in one place.


```typescript
type Action = { type: 'field'; name: keyof Signup; value: string } | { type: 'reset' };

function reducer(state: Signup, action: Action): Signup {
  switch (action.type) {
    case 'field':
      return { ...state, [action.name]: action.value };
    case 'reset':
      return initialSignup;
  }
}

const [form, dispatch] = useReducer(reducer, initialSignup);

<input
  name="email"
  value={form.email}
  onChange={(e) => dispatch({ type: 'field', name: 'email', value: e.target.value })}
/>
```


### Skip state and read FormData on submit


If you only need the values when the form is submitted, you may not need state at all. Leave the inputs uncontrolled and read them with `FormData`. In React 19 you can pass a function to the form's `action` prop and it receives the `FormData` directly.


```typescript
function SignupForm() {
  async function signup(formData: FormData) {
    const data = Object.fromEntries(formData);
    await saveSignup(data);
  }

  return (
    <form action={signup}>
      <input name="name" defaultValue="" />
      <input name="email" type="email" />
      <button type="submit">Sign up</button>
    </form>
  );
}
```


React resets uncontrolled fields after a successful action. Use controlled state when you need live validation, dependent fields or formatting as the user types. For large forms with complex validation, a form library such as React Hook Form saves a lot of code.


## Common pitfalls

- **Missing or mismatched** **`name`** **attributes.** If `name` does not match a state key, the handler creates a new key and the input never updates.
- **Mutating state.** `form[name] = value; setForm(form)` changes the same object, so React may skip the update. Always create a new object.
- **Reading the event inside the updater.** Destructure `name` and `value` before calling `setForm`, so the updater function does not depend on the event object.
- **Switching between controlled and uncontrolled.** Start every field with a defined value, such as an empty string, or React warns that the input changed from uncontrolled to controlled.
- **Nested objects.** Spreading only copies one level. For `address.city`, copy the nested object too, or flatten the form state.

## Related reading

- [React: Updating objects in state](https://react.dev/learn/updating-objects-in-state)
- [React: The input component](https://react.dev/reference/react-dom/components/input)
