Skip to main content

From react-native-web

Your app code stays the same when you move from react-native-web. But react-native-web leaves out some behavior of React Native, so an app often has web-only code for these gaps. Do these steps in order:

  1. Install the package for your setup, and remove react-native-web.
  2. Move your tests, if Jest runs them on the web.
  3. Make the changes for the parts of react-native-web that React Native doesn't have.
  4. Remove the workarounds that aren't necessary now.
  5. Check the behavior that changes with no change in your code.

If you see an error or a warning on the way, find its text in Errors and warnings.

This page compares with react-native-web 0.21.

Install the package for your setup​

Your app runs onDo this
Expo, also with Expo RouterInstall @rootnative/web-expo, remove react-native-web, and wrap your Metro config with withRootNative. See Expo.
The React Native CLI, with a bundler for the webInstall @rootnative/web-metro, and remove react-native-web and the web bundler that you added for it. Metro builds the web app. See React Native CLI.
ViteInstall @rootnative/web, and add its plugin. Remove react-native-web and the alias from react-native to it in vite.config.ts. An entry file that calls AppRegistry.runApplication keeps the call. The app renders with no view around it, so give the root element the flex layout of Mount your app. See Vite and AppRegistry.

You don't change an import of react-native in your code. Each setup sends that name to @rootnative/web on the web.

Move your tests​

Under Jest, Expo's Babel preset and the jest-expo/web preset send each import of react-native to react-native-web. Map react-native and react-native-web to @rootnative/web-expo in your Jest config, or your web tests can't find these files. See Tests for the config.

Changes you make​

Your app usesChange
Flat accessibility props, such as accessibilityDisabledUse the aria-* prop, such as aria-disabled. React Native doesn't have the flat props, so this package drops them. In development, a warning names the prop to use. See Props from react-native-web.
CheckBox, Picker, ProgressBar, or another name that only react-native-web hasUse a library or your own component. These names aren't React Native APIs, so @rootnative/web doesn't export them. Under Expo, they load as stubs that throw on use: see Names that load as stubs.
@expo/html-elementsGive View and Text a role. See Semantic HTML. The library imports internal files of react-native-web, so the bundle fails.

Workarounds you can remove​

In each row, react-native-web leaves out the behavior, and @rootnative/web has it. So web-only code that stands in for the behavior isn't necessary.

Behaviorreact-native-web@rootnative/webRemove
Space on a focused Pressable that isn't role="button"Doesn't press. Only Enter presses.Presses, as Enter does.An onKeyDown that presses on Space. If it calls preventDefault(), it does no harm. Else each Space press calls onPress two times.
Alert.alertDoes nothing.Shows a dialog with the title, the message, and the buttons. See Alert.A window.alert or a window.confirm that stands in for it.
Keyboard events and KeyboardAvoidingViewNo event fires, and KeyboardAvoidingView doesn't move.keyboardDidShow and keyboardDidHide fire for the on-screen keyboard of a phone or a tablet, and KeyboardAvoidingView moves out of its way. See Keyboard.Web-only code that reads the height of the keyboard, for example from window.visualViewport.
snapToInterval and snapToOffsets of a ScrollViewIgnored. Only pagingEnabled snaps.All three snap. With a finger, a pen, or the mouse wheel, the browser's own scroll snap stops the scroll on a snap offset. See ScrollView.scrollSnapType and scrollSnapAlign styles that stand in for them.
onScrollBeginDrag, onScrollEndDrag, onMomentumScrollBegin, and onMomentumScrollEndNever fire.Fire. See ScrollView.Touch events or timers that stand in for them.

Behavior that changes​

These rows change what your app does, with no change in your code.

Behaviorreact-native-web@rootnative/web
AccessibilityInfo.isScreenReaderEnabled()Resolves true.Resolves false, because a browser doesn't tell a page. A feature that shows only for screen reader users doesn't show on the web. See AccessibilityInfo.
RefreshControlRenders a plain view. A pull does nothing.A pull with a finger calls onRefresh. A mouse, a pen, or a keyboard has no pull, so keep a refresh button. See RefreshControl.
A tap outside a focused TextInputThe browser moves the focus, so the keyboard hides.The keyboard stays, as on native. Inside a ScrollView, keyboardShouldPersistTaps decides. See A tap outside the field.
accessibilityRole="search"Renders role="search", the landmark.Renders role="searchbox", the role of a search field, which is React Native's meaning of the name. For a landmark around a search field, use role="search". React Native's Role type doesn't have it, so TypeScript needs a cast. See Semantic HTML.

Libraries written for react-native-web send some props and import some exports that React Native doesn't have, such as hrefAttrs, dataSet, and unstable_createElement. See Compat exports for what this package does with them.

Errors and warnings​

Find the text that you see in the terminal, the test output, or the browser console.

TextWhereCauseDo this
react-native-web is not installed. Some React Native components may not work on web without it.Expo's terminalExpo's CLI looks for react-native-web on each start or export of the web target.Nothing. Don't install react-native-web: the bundle doesn't use it. See Expo.
Unable to resolve "react-native-web/dist/…"MetroA library imports an internal file of react-native-web that the package doesn't have.For @expo/html-elements, see Changes you make. For another library, see Libraries.
Cannot find module 'react-native-web/dist/exports/View', or another react-native-web/dist/… pathJestExpo's Babel preset rewrites each import of react-native to a file of react-native-web, which isn't installed now.Map react-native and react-native-web to @rootnative/web-expo. See Move your tests.
Picker is not in @rootnative/web yet, or the same text with another nameBrowser consoleYour code, or a library, uses a name that only react-native-web has. Under Expo, the name is a stub.Use a library or your own component. See Names that load as stubs.
accessibilityDisabled is a react-native-web prop, or the same text with another flat propBrowser consoleA flat accessibility prop of react-native-web. The package drops it. The warning shows in development.Use the aria-* prop that the warning names. See Props from react-native-web.