(Using JSX Transformer in a browser) When I call a responsive component from a simple javascript, I get a Non-Woven Reference link .
I am trying to call the React.js component (0.12.2) from my javascript application. I got a jQuery document.ready handler for this.
This means that the JSX compiler in the browser takes some time before the reactive components are ready for use.
In this case, Document.ready may not be an option.
See an example below:
index.html
<!DOCTYPE html> <html> <head lang="en"> <script src="jquery-2.1.3.min.js"></script> <script src="react-0.12.2/JSXTransformer.js"></script> <script src="react-0.12.2/react.js"></script> <script type="text/jsx" src="reactComponent.js"/> <script src="app.js"/> </head> <body> <div id="target"></div> </body>
app.js:
$(function () { console.log("app.js: " + typeof MyComponent); init(); });
component.js:
var MyComponent = React.createClass({ render: function () { return (<div>works</div>) } }); function init() { console.log("init: " + typeof MyComponent); React.renderComponent(<MyComponent/>, document.getElementById("target")); }
Running this in a browser logs:
app.js: undefined app.js: Uncaught ReferenceError: init is not defined
But when I load app.js through a jsx transformer, adding type="text/jsx" to the script tag, it works:
app.js: function reactComponent.js: init: function
Is there any other way to wait for the JSX transformer to complete instead of loading all js files of type text/jsx ? And I'm right that this is really browser-specific for the JSX transformer.
source share