const qc = typeof window === "undefined" ? getServerQueryClient() : queryClient;
const historyQuery = qc
.getQueryCache()
// @ts-expect-error Type mismatch on React query
.build(qc, getSessionsHistoryOptions(authenticatedFetcher));
if (!historyQuery.state.data) historyQuery.fetch();
const historyQueryObserver = new QueryObserver<
Pick<Session, "sessionId" | "title" | "createdAt">[]
>(qc, { queryKey: ["sessions"] });
historyQueryObserver.subscribe((result) => {
useSessionsStore.setState({
history: result.data ?? [],
isHistoryLoading: result.fetchStatus === "fetching",
});
});
export const useSessionsStore = create<SessionsStore>((set, get) => ({
...some code
history: typeof window === "undefined" ? historyQuery.state.data ?? [] : [],
...some code
}))
const qc = typeof window === "undefined" ? getServerQueryClient() : queryClient;
const historyQuery = qc
.getQueryCache()
// @ts-expect-error Type mismatch on React query
.build(qc, getSessionsHistoryOptions(authenticatedFetcher));
if (!historyQuery.state.data) historyQuery.fetch();
const historyQueryObserver = new QueryObserver<
Pick<Session, "sessionId" | "title" | "createdAt">[]
>(qc, { queryKey: ["sessions"] });
historyQueryObserver.subscribe((result) => {
useSessionsStore.setState({
history: result.data ?? [],
isHistoryLoading: result.fetchStatus === "fetching",
});
});
export const useSessionsStore = create<SessionsStore>((set, get) => ({
...some code
history: typeof window === "undefined" ? historyQuery.state.data ?? [] : [],
...some code
}))