Menu

1 / 2

Give the agent the existing query-key factory, not stringly-typed query keys

DEV Community: frontend·Sherotree·12 days ago
#chS2WWrh
#devtofrontend#devto#dev#factory#query
Long article (421 words) — no AI summary yet.
Reading 0:00
15s threshold

The PR fetches a resource with ['user', id] or 'user-'+id typed in the component. The repo already has a query-key factory ( queryKeys.user.detail(id) , or a similar helper) that list, detail, and mutation hooks share. The new key does not match, so a successful mutation leaves the list stale, or two hooks for the same entity sit in different cache slots.

I've started treating a handmade query key as a cache bug waiting to happen when a factory exists. The fetch may work in the happy path. Invalidation is why the factory is there.

Why the loose key shows up

Examples online use a string or a short array in the hook. The model can write that without finding queryKeys or keys.ts .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.