New to React Query - unsure how to deal with state management for a multi select search form
I have a form input that allows selecting of multiple users. It's a search input and the user types a username and submits the form, which fires a query that returns a user. This user is then added to a 'selected users' array. I need to display a list of these selected users in my form. What is the colloquial way to access the previous query state, given that the query changes and the
data only contains the user returned by the most recent query? I don't want to duplicate the selected users state in both my store and react query.1 Reply
national-gold•3y ago
I think you need a separate state or store for this. I don't think it's really duplicated: the query contains the last searched user while the store/state contains the list of added users.
You could technically access react query's cache instead, using
getQueriesData to find out all the searched users, but that wouldn't be reactive.