I'm having trouble setting state in an ajax function. An ajax call is looped, and for each iteration a component is rendered, all of which are added to an array. This array will be used to set the state of my component, and then I'll return this.state.toRender as the JSX return which will appear on the DOM.
var self = this;
$.ajax({
success: function(data) {
// generate array of objects
self.setState({toRender: renderArray});
Since JS passes by value, I shouldn't setState of var self, right? Somehow I need to point to the component instead of the ajax call to change the state. A promise didn't seem to have access to the array generated, and I didn't get results using a callback.
The initial state actually goes through the ajax function and returns exactly what I want, but the event (DropDown selection) that is supposed to update state doesn't make any change.
The child component is called in the parent's return:
And in the child component I've added this function:
pick : function(event) {
var selected = event.target.value;
this.setState({list: "all"}, this.props.newSelect('theUrl'));
I know that DropDown selection works because I've used it successfully in earlier stages of the project.