Beginner trick of react-query

Vaibhav Rai
Sep 29, 2022

--

We have a case where we will have to fetch the data based on the props change.

Ideally, we will use the useEffect pass props as a dependency array, but while using react-query we have a huge advantage while dealing with cases like these.

In useQuery of react-query we can pass queryKey and this is a list, so if we pass ["unique-id", prop] then on every change of prop it will fetch the data, not only we avoided manually writing these cases but also it made the code more error-free.

Happy coding.

--

--

No responses yet