What is the best way to check if a given object of any kind is a SyntheticEvent?
Currently, I'm peering into the internals:
if (obj.nativeEvent ) {
// 100% sure...with this version of React
}
What is a more idiomatic (or at least future-proof) way of doing this?
You can use such check: if (!(event instanceof Event))
.
event
(which is SyntheticEvent
) will give false
in this case and event.nativeEvent
will give true
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments