What is the TypeScript definition for the onChange event in React?
The right interface for onChange is ChangeEvent
Please continue reading below to see how to use it or read my guide on using React events with TypeScript.
You can also go to the search page 🔍 to find another event.
For "form" components you will need to use "FormEvent" instead.
Interface
interface ChangeEvent<T = Element> extends SyntheticEvent<T> {
target: EventTarget & T;
}
Full example
import React, { ChangeEvent } from 'react';
const App = () => {
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
// Do something
};
return <input onChange={handleChange}>{/** Some code */}</input>;
};
export default App;