Querying an API for a Details screen without a "details" endpoint
I'm using React Query with an API that has an endpoint where one can get a list of Foo's, but there is no endpoint to get the details of a specific Foo. I have two screens: a List screen and a Details screen. The List screen is set up to use the
The Details screen has no way direct way to get the Details of a Foo, as there is no API endpoint for it. The best option I see is to use
What should I do in this scenario?
useQuery hook and call the API's list endpoint and populate the screen with an entry for each Foo. Each entry is clickable, and clicking will open the Details screen (passing in a unique Foo ID). However, that is where the data stops.The Details screen has no way direct way to get the Details of a Foo, as there is no API endpoint for it. The best option I see is to use
useQuery again, and hope it hits the cache from the List screen (the list endpoint includes all the details), instead of sending out a new request. That still feels like bad data practice, though. A second option would be to use QueryClient.setQueryData to set each individual cache for each Foo, but I feel like that may also be frowned upon from a "best practices" perspective (setting the query data outside the normal way, fetching).What should I do in this scenario?