mirror of
				https://github.com/langgenius/dify.git
				synced 2025-11-04 04:43:09 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			29 lines
		
	
	
		
			889 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			889 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
'use client'
 | 
						|
 | 
						|
import React, { createContext, useContext, useState } from 'react'
 | 
						|
 | 
						|
type ExternalApiPanelContextType = {
 | 
						|
  showExternalApiPanel: boolean
 | 
						|
  setShowExternalApiPanel: (show: boolean) => void
 | 
						|
}
 | 
						|
 | 
						|
const ExternalApiPanelContext = createContext<ExternalApiPanelContextType | undefined>(undefined)
 | 
						|
 | 
						|
export const ExternalApiPanelProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
 | 
						|
  const [showExternalApiPanel, setShowExternalApiPanel] = useState(false)
 | 
						|
 | 
						|
  return (
 | 
						|
    <ExternalApiPanelContext.Provider value={{ showExternalApiPanel, setShowExternalApiPanel }}>
 | 
						|
      {children}
 | 
						|
    </ExternalApiPanelContext.Provider>
 | 
						|
  )
 | 
						|
}
 | 
						|
 | 
						|
export const useExternalApiPanel = () => {
 | 
						|
  const context = useContext(ExternalApiPanelContext)
 | 
						|
  if (context === undefined)
 | 
						|
    throw new Error('useExternalApiPanel must be used within an ExternalApiPanelProvider')
 | 
						|
 | 
						|
  return context
 | 
						|
}
 |