What is the TypeScript definition for the onCompositionUpdateCapture event in React?
The right interface for onCompositionUpdateCapture is CompositionEvent
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.
Composition events get triggered when the user enters text.
The event allows you to access that data through the "data" field.
Interface
interface CompositionEvent<T = Element> extends SyntheticEvent<T, NativeCompositionEvent> {
data: string;
}
Full example
import React, { CompositionEvent } from 'react';
const InputComponent = () => {
const handleCompositionEvent = (e: CompositionEvent<HTMLInputElement>) => {
// Do something
};
return <input value="Some text" onCompositionUpdateCapture={handleCompositionEvent} />;
};
export default InputComponent;