I have a tempAddList that will contain a list of id's that I will set the state into the relInfo table and callback the addRelation function to submit the data. But when I run onAddClick for example if the tempAddList = [2,3,4] it would run addRelation 3 times with the latest setState id 4 but not 2 and 3. How would I get it to run for each individual id.
onAddClick = () => {
this.state.tempAddList.forEach((id) => {
this.setState({
relInfo: {
...this.state.relInfo,
modId: id
}
}, () => this.addRelation());
});
};
addRelation = () => {
EdmApi.insertModifier(this.state.relInfo)
.then(res => console.log(res))
.catch(err => console.log(err));
};