Apollo client: select 1 active option using local state

Viewed 32

I'm rather new to using the apollo client for managing the local state. I was wondering if some of you with more experience could give some guidance on how to do the following:

I'm fetching a list of 4 "categories" using useQuery. Out of those 4 categories, I want to pick 1 "active" one and save it in the local state. Using a category list I want to be able to select the active category. This active category will be used elsewhere to display information.

I came up with a few ideas but was wondering if there is a "best" solution for this:

  1. Save the complete category including nested data in a @client field
  2. Save the id of the active category in a @client field and perform a second query to find the category with that id
  3. Add an active boolean field to the category in the list that is active. When switching categories this active field would have to be changed on both the old and new category
  4. Use good old react useState, but that seems to defeat the purpose
0 Answers
Related