Here is the code: var ShowTop = React.createClass({ render: function(){ var listBoard = recentData.map(function(data){ return ( <tr> <th> {data.position} </th> <th> <a href={data.userLink} target="_blank">{data.username}</a> </th> <th> {data.recent} </th> <th> {data.alltime} </th></tr> ); }); return( <table> <tr> <th>#</th> <th>Camper Name</th> <th>Recent Points</th> <th>All Time Points</th> </tr> {listBoard} </table> ) } });
This code was working, I don’t think I changed anything and then suddenly it stopped working…
I think it may be an issue with the listBoard variable, becuase when I remove it everything works smoothly.
You have no guarantee that by the time your component renders on the page, the AJAX request would have returned the data. That’s why it might sometimes work, but other times the request might take longer to complete.
A common pattern for such situation in React seem to be to move your getData function into the componentWillMount method and once the data is retrieved, assign it to state, so the component will re-render and then you can do something like what @Oxyrus mentioned above