React Native WebView

13.16.1 · active · verified Sun Apr 19

React Native WebView is a community-maintained component designed to embed web content within React Native applications across iOS, Android, macOS, and Windows platforms. It serves as a direct replacement for the WebView component that was previously part of the React Native core, which has since been removed. The current stable version is 13.16.1, with frequent patch and minor releases addressing bugs and adding features, typically on a monthly to bi-monthly cadence. Key differentiators include its broad platform support, compatibility with both the old (paper) and new (fabric) React Native architectures, and official support for Expo. The project actively merges pull requests, demonstrating ongoing development, though explicit support for issues is often community-driven due to the inherent complexity and diverse use cases of WebViews. The library adheres to semantic versioning, introducing breaking changes only in major version bumps.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to render a basic WebView displaying the React Native documentation website. It includes basic styling, a load event handler, and an error handler.

import React from 'react';
import { StyleSheet, View } from 'react-native';
import { WebView } from 'react-native-webview';

const MyWebComponent = () => {
  return (
    <View style={styles.container}>
      <WebView 
        source={{ uri: 'https://reactnative.dev/' }}
        style={styles.webview}
        onLoad={() => console.log('WebView loaded!')}
        onError={(syntheticEvent) => {
          const { nativeEvent } = syntheticEvent;
          console.warn('WebView error: ', nativeEvent.description);
        }}
      />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    marginTop: 20, // Adjust for status bar
  },
  webview: {
    flex: 1,
  },
});

export default MyWebComponent;

view raw JSON →