Type extracted form handlers
A separately declared input handler needs a precise event parameter.
React 19+ · Type Alias
React.ChangeEvent<T> types a React DOM change event for a specific element type. Use it most directly when an extracted handler needs an explicit event annotation.
React.ChangeEvent<T> gives an extracted DOM change-event handler a concrete target element type. For an input, React.ChangeEvent<HTMLInputElement> lets TypeScript understand currentTarget and its value while the handler updates component state.
React.ChangeEvent<T>| Name | Type | Description |
|---|---|---|
T | Element | The DOM element type associated with the change event, such as HTMLInputElement. |
A typed React change-event object; the type alias itself does not return a runtime value.
import { useState } from "react";
export default function Form() {
const [value, setValue] = useState("");
function handleChange(event: React.ChangeEvent<HTMLInputElement>) {
setValue(event.currentTarget.value);
}
return <input value={value} onChange={handleChange} />;
}The handler explicitly receives a change event whose current target is an HTML input.
A separately declared input handler needs a precise event parameter.
A handler reads the changed control's value with element-specific typing.
A callback is assigned to an input's onChange prop.
Use React.ChangeEvent<ElementType>, replacing ElementType with the element that emits the event. For an input, React.ChangeEvent<HTMLInputElement> gives the handler a typed currentTarget and value.
Follow-up: How would you type the callback without annotating its parameter? Use React.ChangeEventHandler<HTMLInputElement> as the callback type.
The generic identifies the target element type, so the handler can safely access properties provided by that element. In the documented input example, currentTarget.value is available through HTMLInputElement.
Follow-up: What should you do when the event is not covered by a specific listed event type? Use React.SyntheticEvent, the common base for React events.
Inline handlers often receive an event type inferred from the JSX prop they are assigned to. A separately declared function generally needs an explicit event annotation when passed to that prop.
Follow-up: What alternative keeps the callback declaration itself typed? Declare it with React.ChangeEventHandler<HTMLInputElement>.
React.ChangeEventHandlerReact.SyntheticEventReact.ChangeEvent<HTMLInputElement>