Skip to main content

Platform

Tells your code which platform it runs on. On the web, Platform.OS is 'web'.

import { Platform } from 'react-native'

const shadow = Platform.select({
web: { boxShadow: '0 1px 3px rgba(0,0,0,0.2)' },
default: { elevation: 2 },
})
MemberOn the web
Platform.OS'web'.
Platform.select(spec)The web value, else the default value. A native key doesn't apply, because the web isn't native.
Platform.VersionThe user agent string of the browser. An empty string on the server.
Platform.constants{ reactNativeVersion }, the React Native release whose API this package matches: 0.88.1.
Platform.isTVfalse.
Platform.isTestingtrue when NODE_ENV (or the bundler mode) is test.
Platform.isDisableAnimationstrue when the user asks for reduced motion (prefers-reduced-motion).

The Vite plugin puts 'web' in place of each Platform.OS read when it builds your app, so the minifier drops the code of the other platforms. Platform.select keeps its code.