Correct way to check if any object is a SyntheticEvent?

Viewed 4192

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?

2 Answers

I check if obj.constructor.name === 'SyntheticEvent'.

Related