2

I have the following resources:

test.js

var gblData;

function getData(){
    //webservice to set value to gblData
}

React jsx file

//use the gblData to render the html page

html file

I tried the following ways to call the getData() before the jsx file so that gblData is not undefined. But it is failed.

1 html body onload function

2 jquery document ready

1
  • try putting your test.js script in the <head> tags of your html page, or you can use the defer attribute on both the script tags to make them execute in order see here Commented Oct 22, 2014 at 17:47

1 Answer 1

1

Is your React.renderComponent call after everything else? Try the following. You can have your jsx file declare all your components, but you can render them from another file.

var glbData;
function getData(){
  ...
  ...
  React.renderComponent(<YourComponent/>, document.body);
}    

Here's a fiddle.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.