How to use await for get request in RTKQuery?

Viewed 1721

I've tried

  • initiate - but this result was retrieved from previous result.
  • mutate - but I think this is irregular.

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.

  • I updated to v1.7
  • use "useLazyQuery" and unwrap()
const [getPokemon] = useLazyGetPokemonQuery()

useEffect(() => {
  getPokemon({...})
    .unwrap()
    .then(data => setValuesToForm(data))
}, [])

Thank you very much...!!

0 Answers
Related