T
TanStack4y ago
yelping-magenta

Query Key factory best practice for filters

Is it ok to keep query key in this format? in here we have used a single key called sortCriteria to keep pagination and filter information. Or is it more advised to create separate keys for each filter keys(more flattened)? Current:
[{"entity":"lists","scope":"question-bundle","sortCriteria":{"order":"desc","page":0,"pageSize":10,"sortBy":"updatedAt"}}]
[{"entity":"lists","scope":"question-bundle","sortCriteria":{"order":"desc","page":0,"pageSize":10,"sortBy":"updatedAt"}}]
Flattened:
[{"entity":"lists","scope":"question-bundle", "order":"desc","page":0,"pageSize":10,"sortBy":"updatedAt"}]
[{"entity":"lists","scope":"question-bundle", "order":"desc","page":0,"pageSize":10,"sortBy":"updatedAt"}]
3 Replies
flat-fuchsia
flat-fuchsia4y ago
I don't think there's any difference when it comes to query targeting, for example for invalidation.
yelping-magenta
yelping-magentaOP4y ago
true, it doesnt affect the query
deep-jade
deep-jade4y ago
I'd make this decision based on the way the data typically exists in your app and what's the most convenient way to consume the query for your components. Is it easier to pass them in as a nested object or flattened?

Did you find this page helpful?