I have tried using ajax call to get data from rails to react but the state was not updating. When I tried to call state it's giving me an error that it is undefined. I have referred other questions in stack overflow but couldn't solve my problem. Here is my my ajax request.
fetchData: function(){
$.ajax({
url: '/orders',
dataType: 'json',
type: 'GET',
success: function(result) {
this.setState({orders: result});
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
}
Click this link to view the error
<p><button onClick={this.fetchData}>Filter</button></p>
<div>
{
Object.keys(this.state.orders).map(function(key){
return <div key={ key }>{this.state.orders[key]}</div>
}, this)
}
</div>