In a React Native WebView, you can use the postMessage method to send messages from the WebView’s JavaScript code to your React Native application. This allows for communication between the WebView and the React Native app.

To send information from webview to react native, you can call postMessage method from webview and it will fire onMessage event in react native application. So that you can easily get any information from webview.

Let’s implement an example with a local html file, we will display one simple button in the webview and on click of that button we will call the post api and send a success response to react native application.


<!DOCTYPE html>
   <h2>POST API DEMO</h2>
   <p id="demo"></p>
   <button onclick="myFunction()">Call API</button>

     function myFunction() {
       var xhr = new XMLHttpRequest();'POST', '', true);
         'application/x-www-form-urlencoded; charset=UTF-8',
       xhr.onreadystatechange = function () {
         if (xhr.status == 201) {
           // calling post message function on success response
           document.getElementById('demo').innerHTML =
             'Success : ' + xhr.responseText;

I have added above html file at below locations,
Android: android/app/src/main/assets/webPage.html
Ios : ios/webPage.html


import React from 'react';
import {Platform} from 'react-native';
import {WebView} from 'react-native-webview';

const htmlPath =
 Platform.OS === 'android'
   ? 'file:///android_asset/webPage.html'
   : 'webPage.html';

function WebViewComp(): JSX.Element {
  assign function to postmessage
  window.ReactNativeWebView.postMessage will give event to onMessage
 const injectedJavascript = `(function() {
   window.postMessage = function(data) {
 return (
export default WebViewComp;

You will get the output in terminal like this,

Terminal Output

Support On Demand!

React Native