Phoelpis Phoelpis - 1 year ago 94
React JSX Question

React Js: How to reload the initial data loaded via ajax?

I get my initial data from an outside JSON in

componentDidMount: function() { .... $.get(jsonfile, function(data) { ....

But the state of "jsonfile" changes via an input.
When the state of "jsonfile" prop changes the render method is invoked again, but I will also want to re-run the
What would be the proper (
) way to do it?

Answer Source

You should abstract away your data fetching. If you put your fetching of data in a separate helper method you can call that method when needed, and it should do the fetching (and later updating) of the state

    componentDidMount: function () {

    fetchData: function () {
        var _this = this;
        $.get('....', function (result) {

    handleClick: function () {

    render: function () {
        return (<div onClick={this.handleClick}>{data}</div>);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download