useThread.tsx raw
1 import threadService from '@/services/thread.service'
2 import { useSyncExternalStore } from 'react'
3
4 export function useThread(stuffKey: string) {
5 return useSyncExternalStore(
6 (cb) => threadService.listenThread(stuffKey, cb),
7 () => threadService.getThread(stuffKey)
8 )
9 }
10
11 export function useAllDescendantThreads(stuffKey: string) {
12 return useSyncExternalStore(
13 (cb) => threadService.listenAllDescendantThreads(stuffKey, cb),
14 () => threadService.getAllDescendantThreads(stuffKey)
15 )
16 }
17