mirror of
				https://github.com/langgenius/dify.git
				synced 2025-10-31 10:53:02 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			28 lines
		
	
	
		
			738 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
		
			738 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { createContext, useContext, useContextSelector } from 'use-context-selector'
 | |
| import { useMitt } from '@/hooks/use-mitt'
 | |
| import { noop } from 'lodash-es'
 | |
| 
 | |
| type ContextValueType = ReturnType<typeof useMitt>
 | |
| export const MittContext = createContext<ContextValueType>({
 | |
|   emit: noop,
 | |
|   useSubscribe: noop,
 | |
| })
 | |
| 
 | |
| export const MittProvider = ({ children }: { children: React.ReactNode }) => {
 | |
|   const mitt = useMitt()
 | |
| 
 | |
|   return (
 | |
|     <MittContext.Provider value={mitt}>
 | |
|       {children}
 | |
|     </MittContext.Provider>
 | |
|   )
 | |
| }
 | |
| 
 | |
| export const useMittContext = () => {
 | |
|   return useContext(MittContext)
 | |
| }
 | |
| 
 | |
| export function useMittContextSelector<T>(selector: (value: ContextValueType) => T): T {
 | |
|   return useContextSelector(MittContext, selector)
 | |
| }
 |