I have a project which does not support generators
and async await
syntax.
I built the following code with async await
because I don't see any other way to do it:
this.setState(async lastState => {
const newImagesAmount = lastState.images.length + 20;
const newImages = await this.getImages(this.props.tag, newImagesAmount);
return {
images: newImages
};
});
Why? In this particular case, the new state is built by both the old state and a result of a promise
.
How can I transform it to non - async await
syntax?
Note (Update):
Due to the fact that both the current answers contain the same bug, please read @dhilt answer + responses first which explain what are the bugs.