What is the TypeScript definition for the onCompositionEnd event in React?

The right interface for onCompositionEnd is CompositionEvent

Please continue reading below to see how to use it or read my guide on using React's events with TypeScript.

Composition events get triggered when the user enters text.

The event allows you to access that data through the "data" field.


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" onCompositionEnd={handleCompositionEvent} />;

export default InputComponent;

Attributes that use CompositionEvent: