so I am trying to pull the lng and lat using geolocation with async and await. For some reason, it didn't wait for the promise to return before passes it to the reducer. I am getting another promise.
I expected to use await to get the result back from the promise before moving on to different parts of the program.
geolocation in reducer gets called before the result of the promise is returned.
You've misunderstood the purpose of a Promise
.
When you create a promise, it does not pause execution of the code. In fact, the entire reason to use a promise is when you want the code to continue it's execution without waiting for a response.
There exist a number of middleware solutions to solving this problem. ReduxThunk
is probably the most popular, but if you prefer a more async-await methodology you can also also tyr redux-asyncy-await
.
A middleware solution such as these is required to handle async data calls.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.