How do you handle global state with RSCs?
Hi
Im having a hard time to understand how you can leverage RSCs for data fetching if the data you want to fetch is dependent on user input.
Case Example
For example. I have rooms in a building you can book. But some rooms can only be accessed by being a manager.
Now, a user can see if a room is booked and who has booked it (booking status field).
But for rooms which can only be accessed by a manager this info us hidden. Except if the user is a manager and is in the "manager" mode (global state).
Question
How do you handle such a case where you want to show the information of a room based on the user's role and mode?
Imagine you need this booking status info in the overview list and then in the whole tree when you have chosen a room to book (and proceed to the next steps). Also, switching manager mode should be instant.
Pre RSCs, I would fetch the whole list of rooms with all the booking state info the user is allowed to see and store it in a context. Then I would render the big component tree, making use of useContext. If a manager turns on the manager mode, I could just switch to show the previously hidden data, without having to refetch.
Is there a way to leverage the power of RSCs for that? Does it even make sense to use RSCs? I enjoy querying my DB directly...
0 Replies