Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React composition events

Tags:

javascript

The React docs specifies three "composition events".

onCompositionEnd onCompositionStart onCompositionUpdate

https://facebook.github.io/react/docs/events.html#composition-events

What does composition imply and when do these events occur?

like image 994
swelet Avatar asked Mar 08 '16 19:03

swelet


People also ask

What is composition events in React?

The DOM CompositionEvent represents events that occur due to the user indirectly entering text. It is not React's own event.

What are composition events?

Composition Events provide a means for inputing text in a supplementary or alternate manner than by Keyboard Events, in order to allow the use of characters that might not be commonly available on keyboard.

Why does React use synthetic events?

Benefits of using synthetic events:Cross browsers applications are easy to implement. Synthetic events are that ReactJS reuses these events objects, by pooling them, which increase the performance.


2 Answers

Those events would fire when you type non-latin characters like Japanese with IME input to "compose" a word with one or more than two letters. I made a simple demo gif below, please take a look to get a better idea. demo of when CompositionEvent occurs

like image 123
Fumiya Shibusawa Avatar answered Sep 30 '22 15:09

Fumiya Shibusawa


The DOM CompositionEvent represents events that occur due to the user indirectly entering text. It is not React's own event.

More info: https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent

like image 43
Andreyco Avatar answered Sep 30 '22 16:09

Andreyco