haixunMaster/lib/refine-session/use-refine-session.ts

25 lines
632 B
TypeScript

"use client";
import { useSyncExternalStore } from "react";
import {
getActiveTopicId,
getDisplayTopicId,
getSession,
getSnapshotVersion,
hasVisibleRefineSession,
subscribe,
} from "./store";
export function useRefineSessionStore() {
useSyncExternalStore(subscribe, getSnapshotVersion, () => 0);
return {
activeTopicId: getActiveTopicId(),
displayTopicId: getDisplayTopicId(),
hasVisibleSession: hasVisibleRefineSession(),
};
}
export function useRefineSession(topicId: string | null) {
useSyncExternalStore(subscribe, getSnapshotVersion, () => 0);
return topicId ? getSession(topicId) : null;
}