In React Native, you can call a JavaScript function inside a WebView using the injectJavaScript method or the injectedJavaScript prop from react-native-webview.

1. Using injectJavaScript Method

  • The injectJavaScript method is used to execute JavaScript after the WebView has loaded.
  • In the following example a button press triggers injectJavaScript, calling myJSFunction inside the WebView.

injectJavaScript

2. Using injectedJavaScript Prop

  • The injectedJavaScript prop executes JavaScript when the WebView initially loads.
  • When the WebView loads, injectedJavaScript runs automatically.

WebView loads

Need Help With React Native Development?

Work with our skilled React Native developers to accelerate your project and boost its performance.

Hire React Native Developers

Support On Demand!

Related Q&A