简体   繁体   中英

React app as an embeddable widget

I built an app using ReactJS and what I want to do now is to embed this app into my websites as a widget (something like Facebook page widget), I thought that I have to deliver a JS code to include the JS file built by React build command but how should I import the CSS file ?!

JS snippet to include my widget :

 <script>
     // Import react main js file
     (function(d, s, id) {
         var js, fjs = d.getElementsByTagName(s)[0];
         if (d.getElementById(id)) return;
         js = d.createElement(s); js.id = id;
         js.src = 'URL to react build js file';
         fjs.parentNode.insertBefore(js, fjs);
     }(document, 'script', 'my-app'));
     // Initiate my App with some config
     window.onload = function() {
        MyApp.init({
            app_id: xxxxx,
            token: xxxxxx
        });
     };
 </script>

But how I dot with the CSS file ?

You can include the whole React app as an if you have a public URL.

Edit: About including CSS file why don't you try to do the same as what you wrote about the js file ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM