Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

storeSelectors.ts

26 lines928 Bytes

1import { type ThreadId } from "@t3tools/contracts";
2import { useMemo } from "react";
3import {
4 selectProjectById,
5 selectSidebarThreadSummaryById,
6 selectThreadById,
7 useStore,
8} from "./store";
9import { type Project, type SidebarThreadSummary, type Thread } from "./types";
10​
11export function useProjectById(projectId: Project["id"] | null | undefined): Project | undefined {
12 const selector = useMemo(() => selectProjectById(projectId), [projectId]);
13 return useStore(selector);
15​
16export function useThreadById(threadId: ThreadId | null | undefined): Thread | undefined {
17 const selector = useMemo(() => selectThreadById(threadId), [threadId]);
18 return useStore(selector);
20​
21export function useSidebarThreadSummaryById(
22 threadId: ThreadId | null | undefined,
23): SidebarThreadSummary | undefined {
24 const selector = useMemo(() => selectSidebarThreadSummaryById(threadId), [threadId]);
25 return useStore(selector);