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

storeSelectors.ts

14 lines616 Bytes

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