mirror of
https://github.com/langgenius/dify.git
synced 2026-03-07 08:35:58 +08:00
20 lines
559 B
TypeScript
20 lines
559 B
TypeScript
'use client'
|
|
|
|
import type { useMitt } from '@/hooks/use-mitt'
|
|
import { noop } from 'es-toolkit/function'
|
|
import { createContext, useContext, useContextSelector } from 'use-context-selector'
|
|
|
|
type ContextValueType = ReturnType<typeof useMitt>
|
|
export const MittContext = createContext<ContextValueType>({
|
|
emit: noop,
|
|
useSubscribe: noop,
|
|
})
|
|
|
|
export const useMittContext = () => {
|
|
return useContext(MittContext)
|
|
}
|
|
|
|
export function useMittContextSelector<T>(selector: (value: ContextValueType) => T): T {
|
|
return useContextSelector(MittContext, selector)
|
|
}
|