mirror of
https://gitee.com/dify_ai/dify.git
synced 2024-11-30 18:27:53 +08:00
23e3413655
Co-authored-by: StyleZhang <jasonapring2015@outlook.com>
29 lines
773 B
TypeScript
29 lines
773 B
TypeScript
'use client'
|
|
|
|
import { createContext, useContext } from 'use-context-selector'
|
|
import { useEventEmitter } from 'ahooks'
|
|
import type { EventEmitter } from 'ahooks/lib/useEventEmitter'
|
|
|
|
const EventEmitterContext = createContext<{ eventEmitter: EventEmitter<string> | null }>({
|
|
eventEmitter: null,
|
|
})
|
|
|
|
export const useEventEmitterContextContext = () => useContext(EventEmitterContext)
|
|
|
|
type EventEmitterContextProviderProps = {
|
|
children: React.ReactNode
|
|
}
|
|
export const EventEmitterContextProvider = ({
|
|
children,
|
|
}: EventEmitterContextProviderProps) => {
|
|
const eventEmitter = useEventEmitter<string>()
|
|
|
|
return (
|
|
<EventEmitterContext.Provider value={{ eventEmitter }}>
|
|
{children}
|
|
</EventEmitterContext.Provider>
|
|
)
|
|
}
|
|
|
|
export default EventEmitterContext
|