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

Dmitry Shvedov
  • 3,169
  • 4
  • 39
  • 51
EdwardCPF
  • 57
  • 2
  • 9
  • try putting your ```test.js``` script in the `````` 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](http://stackoverflow.com/questions/436411/where-is-the-best-place-to-put-script-tags-in-html-markup) – trekforever Oct 22 '14 at 17:47

1 Answers1

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.

GGhe
  • 663
  • 5
  • 17