-
This project looks so promising but as redux user, I ask myself a lot of questions. Take this simple situation I have a list with items. Fine I will create a useQuery request to fetch my data and render the list. Great too easy... Now I wanted to be able to select an item and for example display the label of the selected item at the top on my header bar. Of course my header bar isn't a children of my list. With redux I will simply use an action->reducer->selector that return my current item selected on the top. And my component will be re-render each time the selection change. But with react-query how I'm supposed to do that ? Use redux as a client state to store the selected ID then use a selector to get the ID and use QueryCache to get all items then filter by the selected one. it seems very complicated for not much. Using a context ? There are some solutions but to me nothing great. So what is the good practice ? What I'm supposed to do ? I think that split server state and client state on the paper is really promising. But in reality with complex application this is something much more complicated to implement. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi 👋 I think you are missing an important point a bit: same as you would call
This is a simple start that should work for many many apps and situations. Of course there are perf / rendering improvements possible, like using tracked queries to avoid re-rendering when only the query status changes (in case you are not needing it), applying The case where you only have a list endpoint, but not a corresponding detail endpoint are further quite rare, so most of the time, the Hope that explains it a bit :) |
Beta Was this translation helpful? Give feedback.
Hi 👋
I think you are missing an important point a bit: same as you would call
useSelector
, you calluseQuery
wherever you want in your app to retrieve the list. if the selected id is client state and you want to store it in redux to make it globally available, that's fine. Here is how I would probably solve your use-case with react-query and redux:useMySelectedItem
is now subscribed to the selectedItem in redux, as well as the list data co…