React 15 + Typescript: React.FormEvent <T> Samples Are Incomplete?

The onChange attribute for the textarea form requires React.EventHandler<React.FormEvent<HTMLTextAreaElement>>.

Down the rabbit hole and we find that

interface EventHandler<E extends SyntheticEvent<any>> {
    (event: E): void;
}

type FormEventHandler<T> = EventHandler<FormEvent<T>>;

/* ... */

interface FormEvent<T> extends SyntheticEvent<T> {
}

In other words, onChange just wants a function that accepts a FormEvent and returns void, and FormEvent is currently identical to SyntheticEvent.

The problem is that SyntheticEvent<T>.target: EventTargetthey EventTargetdo not determine value.

I noticed that there is also currentTarget: EventTarget & Twhere T is HTMLTextInputArea, and the value seems to be defined. But form processing pages render event.target , not event.currentTarget. Who cares? Do I have to follow print shops or a document?

: . currentTarget - , , target - , , . , currentTarget, , , , .

+4

Source: https://habr.com/ru/post/1662212/


All Articles