Help and guidance asked for optimizing TanStack-Query usage with dynamic queries #6476
Unanswered
bartschriever
asked this question in
Q&A
Replies: 1 comment
-
passing like you do it seems fine. Please just make sure that
still the same. define dependencies in the key (long, lat) correctly and it should work out of the box. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi All!
I'm really enjoying using tanstack-query in our frontends. Currently, I find myself occasionally struggling to determine the correct approach for utilizing tanstack-query. I'll provide an example below and hope that the community and/or the tanstack team can provide feedback or suggest a better direction.
I am building a new widget that allows customers to select a package pickup point for their deliveries instead of having them delivered to their homes. Within this Pickup Point (PUP) widget, we have a list of PUPs and a Google Maps overview, utilizing the Google Maps API, displaying all the markers indicating the locations of those PUPs. To better understand what I'm building, please refer to this screenshot of the already-built frontend.
First, we have a query that retrieves addresses from the customer's address book. In this address book, the customer has a default shipping address.
We take this default shipping address and pass it to the Google Maps Geocoding API to obtain the longitude and latitude of this address.
We need the longitude and latitude to retrieve all the pickup points in a radius from this address when the customer opens the widget for the first time. This is because most customers use a PUP when they are not at home during a package delivery, and they prefer it to be delivered close to their home so they can pick it up after work.
Next, we move on to the next query, retrieving all the PUPs.
My first question would be: should you execute the
useGetCustomerAddressesQuery
, get the default shipping address, pass it to the Google Maps Geocoding API to get the longitude and latitude and pass those values to theuseGetPickupPointsQuery
as props or do we execute this piece of code inside theuseGetPickupPointsQuery
?Let's make it a bit more complex. We also have a search bar where people can enter a different address, as we only show the PUPs in a radius of 15 kilometers around the default shipping address. We first fetch the longitude and latitude of this entered address using the Google Maps Places API. Once we have those values, we need to use them with
useGetPickupPointsQuery
to fetch the new PUPs in another area in the entered city, state, or country.I'm not completely sure how I'm going to tackle this problem and hope you guys can help me out a little! If you need more information, please let me know.
Thanks in advance!
Bart
Beta Was this translation helpful? Give feedback.
All reactions