Correct way to check if any object is a SyntheticEvent?

Ashley Coolman

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?

lunochkin

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.

edited at
0

Comments

0 comments
Login to comment

Related

What's the correct way to check if an object is a typing.Generic?

Correct way to check if a type is Nullable

Correct way to pass prototype to an object

Correct way to lock the dictionary object

In scala, is there any way to check if an instance is a singleton object or not?

Check if `Any` value is object

Is there any way to check if an object is a type of enum in TypeScript?

Correct way to check if DocumentDB object exists

Correct way of object destructuring

Is there any way to check if migrations are ended

Is there a way to check if any existing object contains a specific string paramater?

Correct way to check for a key inside JSON object

Is there any way to check if there is a null value in an object or array? mocha - chai

Check if any property in a object is empty

Is there any way to check whether an object is serializable or not in java?

Any way to check an object if its breeze entity object?

Is there any way to correct using socialshare links on localhost?

what is the correct way to check for False?

My RegEx is losing data, any way to correct?

What is the correct way to check object's property if object not undefined in angular 2 template?

What is the correct way to check an object's type in a conditional statement - python

Correct way to check if object is decimal

What would be the best way to check if any of the keys in an array of objects contain a value from an object of arrays array?

Is there any safe way to check the deep of object's property?

Any way to loop through an object of arrays more efficiently to check for errors in function arguments?

Is this the correct way to deallocate a new object?

check if object is exception of any kind

Is there any alternative way of Q object?

correct way to represent any object in Typescript