T
TanStack•4y ago
graceful-blue

Objects as parameters and keys

Reading this interesting use case i was wondering about queries that are already formated as objects. Let's imagine my queries are like this: get({thing: 'todo'}) => get all todos get({thing: 'todo', id: '0x111'}) => get specific todo get({thing: 'todo', filter: { status: 'done'}}) => get all dones get({thing: 'todo', sort: {date: asc}, limit: 10, filter: { status: 'done'}}) => get all dones I guess being already object, i could use directly for keys? What would will happen if i have all todos in the cache, and then i run get({thing: 'todo', id: '0x111'}). Will the elements consuming get({thing: 'todo'}) also show the updates of the todo '0x111' without refetching that query?
2 Replies
probable-pink
probable-pink•4y ago
Leveraging the Query Function Context
Use what React Query provides for optimal type safety
graceful-blue
graceful-blueOP•4y ago
Yep i was inspired by that. My only questio nwas about the keys being able to help react query to update crossed caches. So the key [{thing: todo, id: 7}}] updating the data cache of the key [{thing: todo}] automatically, but per your answer in the question "How to update segments of cache...." i guess even with this structure of keys we still need to manually update caches or invalidate impacted queries? 🤔

Did you find this page helpful?