Skip to content

useReactNativePlatformComponents

biome.json
{
"linter": {
"rules": {
"nursery": {
"useReactNativePlatformComponents": "error"
}
}
}
}

Ensure that platform-specific React Native components are only imported in files named for that platform.

Some React Native components only work on one platform. For example, ProgressBarAndroid is Android-only and ActivityIndicatorIOS is iOS-only. These components should live in files with a matching platform suffix such as .android.js or .ios.js, so the React Native bundler can ship the right code to each platform.

This rule reports an error when a platform-specific component is imported in a file that does not have the matching suffix, or when both Android and iOS components are imported in the same file.

Importing an Android component in a non-Android file:

import { ProgressBarAndroid } from "react-native";
code-block.js:1:10 lint/nursery/useReactNativePlatformComponents ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Android component ProgressBarAndroid is used outside of an Android-specific file.

> 1 │ import { ProgressBarAndroid } from “react-native”;
^^^^^^^^^^^^^^^^^^
2 │

Platform-specific components produce incorrect bundles when imported in shared files.

Move this import to a file with an Android-specific suffix (e.g. .android.js).

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Importing an iOS component in a non-iOS file:

import { ActivityIndicatorIOS } from "react-native";
code-block.js:1:10 lint/nursery/useReactNativePlatformComponents ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

iOS component ActivityIndicatorIOS is used outside of an iOS-specific file.

> 1 │ import { ActivityIndicatorIOS } from “react-native”;
^^^^^^^^^^^^^^^^^^^^
2 │

Platform-specific components produce incorrect bundles when imported in shared files.

Move this import to a file with an iOS-specific suffix (e.g. .ios.js).

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

import { View } from "react-native";

A list of glob patterns to identify Android-specific files.

Default: ["**/*.android.{js,jsx,ts,tsx}"]

In the following example, Android files use .droid.jsx as their suffix instead of the default .android.js:

biome.json
{
"linter": {
"rules": {
"nursery": {
"useReactNativePlatformComponents": {
"options": {
"androidPathPatterns": [
"**/*.droid.jsx"
]
}
}
}
}
}
}
Button.droid.jsx
import { ProgressBarAndroid } from "react-native";
Button.android.jsx
import { ProgressBarAndroid } from "react-native";
/Button.android.jsx:1:10 lint/nursery/useReactNativePlatformComponents ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Android component ProgressBarAndroid is used outside of an Android-specific file.

> 1 │ import { ProgressBarAndroid } from “react-native”;
^^^^^^^^^^^^^^^^^^
2 │

Platform-specific components produce incorrect bundles when imported in shared files.

Move this import to a file with an Android-specific suffix (e.g. .android.js).

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

A list of glob patterns to identify iOS-specific files.

Default: ["**/*.ios.{js,jsx,ts,tsx}"]

In the following example, iOS files use .apple.jsx as their suffix instead of the default .ios.js:

biome.json
{
"linter": {
"rules": {
"nursery": {
"useReactNativePlatformComponents": {
"options": {
"iosPathPatterns": [
"**/*.apple.jsx"
]
}
}
}
}
}
}
Button.apple.jsx
import { ActivityIndicatorIOS } from "react-native";
Button.ios.jsx
import { ActivityIndicatorIOS } from "react-native";
/Button.ios.jsx:1:10 lint/nursery/useReactNativePlatformComponents ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

iOS component ActivityIndicatorIOS is used outside of an iOS-specific file.

> 1 │ import { ActivityIndicatorIOS } from “react-native”;
^^^^^^^^^^^^^^^^^^^^
2 │

Platform-specific components produce incorrect bundles when imported in shared files.

Move this import to a file with an iOS-specific suffix (e.g. .ios.js).

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.