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

export default InputComponent;

Attributes that use CompositionEvent:

Get notified about new tutorials

Join over 1,000 developers who receive React and JavaScript tutorials via email.

No spam. Unsubscribe at any time.