Platform specific imports

Wow, I can’t believe I didn’t try that. That’s exactly what I’m looking for!!! Trying it now and it’s working so far.

import { Platform } from "react-native";

let Branch, BranchEvent;

if (Platform.OS !== 'web') {
  Branch = require('react-native-branch').default;
  BranchEvent = require('react-native-branch').BranchEvent;
}

export default Branch;
export { BranchEvent };
import { Platform } from "react-native";

let MapView, Marker;

if (Platform.OS !== 'web') {
  MapView = require('react-native-maps').default;
  Marker = require('react-native-maps').Marker;
}

export default MapView;
export { Marker };
import { Platform } from "react-native";

let Segment;

if (Platform.OS !== 'web') {
  Segment = require('expo-analytics-segment');
}

export default Segment;
3 Likes