-
Notifications
You must be signed in to change notification settings - Fork 125
Closed
Description
Types aren't coming through in the useLiveQuery hook. data here needs to be cast to Message[].
import {
createCollection,
localOnlyCollectionOptions,
useLiveQuery
} from "@tanstack/react-db";
import { z } from "zod";
const MessageSchema = z.object({
id: z.number(),
text: z.string(),
user: z.string(),
});
export type Message = z.infer<typeof MessageSchema>;
messagesCollection = createCollection(
localOnlyCollectionOptions({
getKey: (message) => message.id,
schema: MessageSchema,
})
);
export function useMessages() {
const { data: messages } = useLiveQuery((q) =>
q.from({ message: messagesCollection }).select(({ message }) => ({
...message,
}))
);
return messages as Message[];
}Metadata
Metadata
Assignees
Labels
No labels