Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native: How to add script tag in the component

I am trying to add tag inside the component for the React Native app. Below is my code and it doesn't seem to work. Could anyone please tell me how to solve this issue?

import React, {Component} from 'react';
import PropTypes from 'prop-types';
import Dimensions from 'Dimensions';
import {StyleSheet, View, TextInput, Image, Text} from 'react-native';

export default class Chatbot extends Component {
  render() {
    return (
      <View>
        <Text>Testing</Text>
        
		<script type="text/javascript">
		    window.__be = window.__be || {};
		    window.__be.id = "5b3a47b4b30a36000769d821";
		    (function() {
		        var be = document.createElement('script'); be.type = 'text/javascript'; be.async = true;
		        be.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.botengine.ai/widget/plugin.js';
		        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(be, s);
		    })();
		</script>

      </View>
    );
  }
}
like image 475
Eunicorn Avatar asked Nov 07 '22 05:11

Eunicorn


1 Answers

You cannot execute code depending on browser environment on react-native. try to run it inside a WebView component. https://facebook.github.io/react-native/docs/webview.html

like image 195
Filipe Borges Avatar answered Nov 15 '22 05:11

Filipe Borges