Is a single item collection a valid pattern?
Hi!
I really love the benefits that DB brings on top of Query. Especially the optimistic updates!
However, I’ve been struggling to understand the mental model around single item collections, like user data.
Should I create a users collection with a single item, and wrap the returned data from queryFn into an array to conform to an array?
Having to specify the user id every time I want to get or update the user seems very boilerplaty too.
On the other hand, I love optimistic updates in DB so much that I’d be fine treating the usersCollection as a table and cope with it.
I found this issue from Kyle that seems to relate to this, but it appeared to focus more on helping with client state than server state.
I really love the benefits that DB brings on top of Query. Especially the optimistic updates!
However, I’ve been struggling to understand the mental model around single item collections, like user data.
Should I create a users collection with a single item, and wrap the returned data from queryFn into an array to conform to an array?
Having to specify the user id every time I want to get or update the user seems very boilerplaty too.
On the other hand, I love optimistic updates in DB so much that I’d be fine treating the usersCollection as a table and cope with it.
I found this issue from Kyle that seems to relate to this, but it appeared to focus more on helping with client state than server state.
GitHub
Summary Introduce a slimmed-down API built on top of TanStack DB's collection system that can replace useState, Redux, Zustand, and other state management solutions. Each "item" would...