TanStackT
TanStack3mo ago
14 replies
endless-jade

creating an empty collection and ready state

I'm having this issue where i'm basically creating a collection from another one, for instance

const subCollection = createCollection(
  queryCollectionOptions({
    queryClient: queryClient,
    queryKey: ['...'],
    queryFn: async () => {
      return [] as PullRequestStatus[];
    },
    getKey: item => item.id,
  }),
);


const mainCollection = createCollection(
  queryCollectionOptions({
    queryClient: queryClient,
    queryKey: ['sync'],
    queryFn: async () => {
      const { data } = await http
        .get(`sync`)
        .json();

      data.forEach(data => {
        subCollection.utils.writeUpsert(data.subData);
      });

      return data
    },
    getKey: item => item.id,
  })


the objective of this is to populate this collection with the data from the other, and then via an SSE, start updating those elements as necessary. basically this collection does not do a sync of any type.

however, with this i'm getting an error:

SyncNotInitializedError: Collection must be in 'ready' state for manual sync operations. Sync not initialized yet.


when trying to write on to it. any ideas?
I think I can circumvent this whole thing but I'm wondering if this might be a bug?
Was this page helpful?