set default `exact` option
Hey!
for most of my use-cases, I wanna do
is there a way for me to set
exact: true by default across the board? instead of setting separately?
couldn't find a way to do it by myself10 Replies
reduced-jade•3y ago
nope. How do your queryKeys look like? A little restructure might help
optimistic-goldOP•3y ago
well, generally the http call itself really inspires the key.
but generally speaking, most of the time I have a
The orgId is sort of a prefix for context,
while using my app, a user can be assocaited to several "organizations", and move between them (and they're completely unrelated with completely different data, that's why it felt important to contextualize).
So say, when I create a new todo
I wanna
or when I remove a todo, I only want to do
I don't want all todos in the world to be refetched
does this make sense? am I going with a "correct" approach?
Also - it doesn't really help that there're no examples / calrification as to what does
exact: false match with 😰reduced-jade•3y ago
So, if you refetch
queryKey: todoKeys.all, I'd expect everything todo-related to be refetched (the list and the details). At least from reading the code. So I'd probably structure a bit more, like:
If I want to refetch the list, I'd do:
and then no "exact" is neededoptimistic-goldOP•3y ago
but then every "single" todo would be refetched, no?
since that's what "inclusive" means, or am I misunderstanding?
if my filter is [{ orgId }, 'todos'], and say this is my cache (figuratively)
all of these would match the given filter, right?
also - I didn't get why separating between
all and list gives any benefit 😅
sorry for my cluelessnessreduced-jade•3y ago
none of them would match 🙃
let's take a step back
optimistic-goldOP•3y ago
updated the filter 🥴
typo
reduced-jade•3y ago
and say this is your cache:
you have one todo list, where all your todos are in, and two detail entries.
Now you can:
- target all 3 with:
[{ orgId }, 'todos'] (that's the ALL key)
- target just the list with [{ orgId }, 'todos', 'list']
- target both details with [{ orgId }, 'todos', 'detail']
- target one detail by id with [{ orgId }, 'todos', 'detail', { id }]optimistic-goldOP•3y ago
ah ha,
so we in advance, notate our keys explicitly
I thought that "telling the story" of the data with just the params is good enough
interesting
reduced-jade•3y ago
it's about forming a hierarchy, depending on how you want to target them with query invalidation / refetches
optimistic-goldOP•3y ago
I see
thanks a lot @TkDodo 🔮 !