Phoelpis Phoelpis - 8 months ago 55
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?


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>);