Answer the question
In order to leave comments, you need to log in
Featch post request chain?
Good afternoon.
There is a request that sends information to the database, this object can be from one or more objects.
I can’t send everything at once, I need to send objects from the date in turn, receive a response, assign the key, then the same manipulations themselves only with the next object in the date.
How to do this, please tell me, I have never done this before. It seems like I understood that I need to make a chain of requests on promises, but I have not yet found a normal example.
export const setFileMovie = (data) => {
return async dispatch => {
const movie = {...data};
const response = await fetch(
'https://skachkov-webby.firebaseio.com/movies_information.json',
{
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(movie)
}
);
const { name } = await response.json();
movie.key = name;
dispatch({
type: SET_MOVIE,
payload: { movie }
});
};
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question