Bluesky app fork with some witchin' additions 馃挮
witchsky.app
bluesky
fork
client
1import {createContext, useContext} from 'react'
2
3import {
4 type createPostThreadOtherQueryKey,
5 type createPostThreadQueryKey,
6} from '#/state/queries/usePostThread/types'
7
8/**
9 * Contains static metadata about the post thread query, suitable for
10 * context e.g. query keys and other things that don't update frequently.
11 *
12 * Be careful adding things here, as it could cause unnecessary re-renders.
13 */
14export type PostThreadContextType = {
15 postThreadQueryKey: ReturnType<typeof createPostThreadQueryKey>
16 postThreadOtherQueryKey: ReturnType<typeof createPostThreadOtherQueryKey>
17}
18
19const PostThreadContext = createContext<PostThreadContextType | undefined>(
20 undefined,
21)
22
23/**
24 * Use the current {@link PostThreadContext}, if one is available. If not,
25 * returns `undefined`.
26 */
27export function usePostThreadContext() {
28 return useContext(PostThreadContext)
29}
30
31export function PostThreadContextProvider({
32 children,
33 context,
34}: {
35 children: React.ReactNode
36 context?: PostThreadContextType
37}) {
38 return (
39 <PostThreadContext.Provider value={context}>
40 {children}
41 </PostThreadContext.Provider>
42 )
43}