I know how to get a parent function to run if you trigger it on a onClick event (or similar), but I want to trigger it on ajax success. So pretty much this constallation:
var parent = React.createClass({
someFunction: function(){
console.log("Parent function triggered");
},
render: function(){
return (
<Child callback={this.someFunction} />
);
}
});
var child = React.createClass({
getInitialState: function(){
return { data: "Wat" };
},
componentDidMount: function(){
$.ajax({
url: "some_url",
method: 'POST',
data: this.state.data,
success: function(response){
this.props.callback; // This is what I would like to do
},
error: function(){
console.log("Couldn't do it cap'n");
}
});
},
render: function(){
return(
<div>Hello!</div>
);
}
});
I could do it by triggering an event, but surely it should be possible to do it when I have access to the function. The function is also passed down correctly, and I can see it as a function if I do a console.log(this.props.callback);