Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Load script funtion inside expo web

$
0
0

I am trying to load a script for true conversion, something like the following (I changed it a bit just to show as an example):

<script type="text/javascript">        var _tip = _tip || [];        (function(d,s,id){            var js, tjs = d.getElementsByTagName(s)[0];            if(d.getElementById(id)) { return; }            js = d.createElement(s); js.id = id;            js.async = true;            js.src = d.location.protocol +'srcTrueConvrsion.js';            tjs.parentNode.insertBefore(js, tjs);        }(document, 'script', 'ti-js'));</script>

I want to support the native(ios, android) in my app but also the web version. So I ended up doing something like this:

  function getTrueConversionScript() {    return `<script type="text/javascript">        var _tip = _tip || [];        (function(d,s,id){            var js, tjs = d.getElementsByTagName(s)[0];            if(d.getElementById(id)) { return; }            js = d.createElement(s); js.id = id;            js.async = true;            js.src = d.location.protocol +'trueConversionSrc.js';            tjs.parentNode.insertBefore(js, tjs);        }(document, 'script', 'ti-js'));</script>    `  }  {Platform.OS === 'web' ? (<View      dangerouslySetInnerHTML={{        __html: getTrueConversionScript(),      }}    />  ) : (<WebView      javaScriptEnabled      source={{        html: getTrueConversionScript(),      }}    />  )}

If I try to use the webView for the web version in expo, I get the following error:

React Native WebView does not support this platform.

So I ended up trying to use dangerouslySetInnerHTML but seems like it is not a property of the View tag as typescript complains.

Any other solution to solve this?

Thanks!


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>