PDA

View Full Version : Using an external library with a dependency on React



j.ashworth
3 Sep 2017, 1:23 AM
I want to include in my fiddle (https://fiddle.sencha.com/?extreact#view/editor&fiddle/262n) an external library (Recompose (https://github.com/acdlite/recompose)) that has a dependency on React.

Is there a better way to do that than by including the React bundles ahead of time?

(see the comment in the index.html)

thanks

mitchellsimoens
6 Sep 2017, 5:10 AM
Fiddle isn't meant to be a full application development tool so certain things won't work as you'd like. For example, the code in index.html will get inserted within the generated <body> so it's not a full index.html. For react, what I do with the reactor stuff is I load react and babel from CDN and provide my own require function. For a short cut, if you wanted react you could check the reactor package (so long as you are using 6.5 modern it should be there) and that will allow you to use react.

For any other external libraries, it needs to be hosted somewhere that you can load it from. If you want the asset to be loaded in the <head>, index.html won't work for you. Instead, you can right-click on the Assets node in the file tree and select the remote javascript option. This will ask for a url to load and it will be loaded in the <head> before the framework assets I believe.

j.ashworth
7 Sep 2017, 10:48 PM
Thanks for the reply.

My fiddle is an ExtReact demo so already has the reactor package checked.

The problem is that, if you take the two React <script>s out of index.html, then React is not defined at the point Recompose is loaded.

I tried including Recompose using the remote JavaScript option under Assets, and I tried putting it in index.html but neither worked unless I first included React ahead of Recompose in index.html. But since reactor already requires React, I was hoping I wouldn't have to do the same thing separately.

I do appreciate that Sencha Fiddle isn't intended to be a full application development tool but for anyone evaluating or learning to use ExtReact, it's very useful to be able to try things out very quickly with libraries like RxJS, Redux and Recompose without having to download or npm install anything. (This can make all the difference in some industry sectors.)

thanks

SarbjitGrewal
20 Sep 2017, 1:15 AM
It doesn't include full web application.