React Native for Web is a library that enables developers to run React Native components and APIs directly on the web using React DOM. It aims to maximize code reuse between native mobile and web platforms, providing a unified API surface that abstracts away platform-specific implementation details. The current stable version is 0.21.2, with minor releases occurring relatively frequently, indicating active development. Key differentiators include its ability to directly interpret React Native's styling system (Yoga layout), accessibility APIs, and core components for web rendering, thereby allowing a single codebase to target multiple platforms, distinct from approaches that require separate web components or extensive platform-specific logic.
npm install react-native-webVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates a basic React Native component rendered on the web using React Native for Web, including component registration and rendering to a specified DOM element.
Avoid using `findNodeHandle` in web-targeting code; consider alternative approaches for DOM node access or refactor to use web-specific APIs where necessary.
Ensure your target audience's browsers meet the new minimum requirements or consider transpilation/polyfills for broader compatibility, though full functionality is not guaranteed.
Review server-side rendering setup to ensure correct style extraction and injection. You may need to adapt your build process to account for the earlier style insertion phase.
Update usage of `I18nManager` from `I18nManager.isRTL` to `I18nManager.getConstants().isRTL`.
Ensure your build configuration (e.g., `babel-plugin-module-resolver`, Webpack aliases) is set up to alias `react-native` to `react-native-web` for web targets.
Add `babel-plugin-module-resolver` or a Webpack alias to your build configuration to map `react-native` to `react-native-web` for web builds.
Remove all calls to `findNodeHandle` from your codebase targeting the web. Consider using `ref` for direct DOM access or alternative web-specific APIs.
Ensure `react-dom` peer dependency is `^18.0.0 || ^19.0.0` and that your application entry point uses `ReactDOM.createRoot` instead of `ReactDOM.render` for React 18 and newer.
Implement proper checks (e.g., `typeof document !== 'undefined'`) around client-specific code or use a library for SSR that provides a simulated DOM environment.