How do I know if my code is running as React Native
Here is how to check if code is on web, nodejs, or react-native:
if (typeof document !== 'undefined') {
// I'm on the web!
}
else if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
// I'm in react-native
}
else {
// I'm in node js
}
Sources:
- What causes node to return 'navigator is not defined'
- Add way to detect react-native (and platform) without require().
- React Native support is broken