Replies: 2 comments 9 replies
-
You use React Query to fetch server-data only and the visibility of the buttons is a UI state (except you want to persist it) so it should not come from RQ and instead your component should have it as a normal state. |
Beta Was this translation helpful? Give feedback.
-
I'm new to react-query and struggling with this intersection of server state and client state as well. My scenario (simplified) is as follows: Let's say I fetch a list of dogs and a list of cats from the server. I get those as arrays like so:
In the SelectFromList component a user should be able to click on an animal and toggle a "selected" boolean True or False. When they click on the "Submit" button it should send all their animal selections to the server. Assume that the list of Cats and the list of Dogs might change on query refetches. How would you go about implementing this in a world where Server State and Client State are separate? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm building a Map component, querying an API for map and GeoJSON data.
The map has multiple layers that can be toggled between visible/hidden on the client side.
The layers data displayed here is data returned from useQuery, stored in the cache, but, when I toggle the layers its visible state is stored on the client side. Each layer has a
visibleByDefault
attribute as well asboundary co-ordinates
(layer will only have the ability to be visible within this boundary) specified in the API responseI know the answer is probably simple, but I'm a little confused as of how to implement this? Do I create some client state,
hiddenLayers
, and1 - on fetch success, add ID of all layers where
visibleByDefault === true
2 - when a user toggles a layer add ID
Beta Was this translation helpful? Give feedback.
All reactions