patochemP
Convex Community3y ago
7 replies
patochem

Problems using useQuery inside a Context

I'm pretty new to React so please forgive me if what I am asking is obvious to most of you.

This is the context (very simplified):
- I have several tables of related elements, organized in a hierarchical way (see example below)
Main = {
  countryId: GenericId<'countries'>,
  cityIds: GenericId<'cities'>[],
  ...
}

- I have a navBar on which I can select a Main object from a list. Selecting an Item gives me its ID
- In my main page, I want to display the different components of a Main object (referenced by the previously selected ID),
- therefore, I need to gather this data from the database (ie: the Main object, the Country referenced by the countryId and the cities references by the cityIds[])

Since I will need to use several Components to display everything, I don't want to be passing props all along and need to create a Context that wraps my page, to provide access to all the necessary info in one place.

However, although the mainId wouldn't change, its countryId could change. How would I detect this change in my context and re-query the planet data for the same Main object?
Was this page helpful?