I've tried
Is there any way to use await for a normal get request?
relevant questions:
Specifically, I want to do the following:
useEffect(() => {
someRTKQuerysGetMethod()
.then(data => setValuesToForm(data))
}, [])
However, the comment I received from phry may have solved the problem.
const [getPokemon] = useLazyGetPokemonQuery()
useEffect(() => {
getPokemon({...})
.unwrap()
.then(data => setValuesToForm(data))
}, [])
Thank you very much...!!
You can use the useLazyQuery hook with the unwrap method.
// Get the trigger
const [getPokemon] = useLazyGetPokemonQuery();
// Then you can call with await
await getPokemon().unwrap();
// Or with standard promise
getPokemon()
.unwrap()
.then((fulfilled) => console.log(fulfilled))
.catch((rejected) => console.error(rejected));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With