DEV Community


Discussion on: WebView — Navigation and data flow with WebViews in a React Native app

digitlninja profile image
digitalninja • Edited

Hey man, great article. Ive tried to get data from RN to my WebApp but am not winning.
Where did you add the eventListener exactly?

Heres my gist

mukeshmandiwal profile image
Mukesh Mandiwal Author • Edited

Sample data you want to pass from react  native to web 

const runFirst = ` = 'green';
      setTimeout(function() { window.alert(JSON.stringify([
             'React Naitve',
             'Node js',
          ])) }, 1000);
      true; // note: this is required, or you'll sometimes get silent failures

 source={{ uri: 'http://localhost:3000' }} // your webview  source
 injectedJavaScript={runFirst}  // pass data to web from react native

 /* In your webview now you can access using  */
  document.addEventListener("message", function(data) {