external-api-panel-context.tsx 889 B

12345678910111213141516171819202122232425262728
  1. 'use client'
  2. import React, { createContext, useContext, useState } from 'react'
  3. type ExternalApiPanelContextType = {
  4. showExternalApiPanel: boolean
  5. setShowExternalApiPanel: (show: boolean) => void
  6. }
  7. const ExternalApiPanelContext = createContext<ExternalApiPanelContextType | undefined>(undefined)
  8. export const ExternalApiPanelProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
  9. const [showExternalApiPanel, setShowExternalApiPanel] = useState(false)
  10. return (
  11. <ExternalApiPanelContext.Provider value={{ showExternalApiPanel, setShowExternalApiPanel }}>
  12. {children}
  13. </ExternalApiPanelContext.Provider>
  14. )
  15. }
  16. export const useExternalApiPanel = () => {
  17. const context = useContext(ExternalApiPanelContext)
  18. if (context === undefined)
  19. throw new Error('useExternalApiPanel must be used within an ExternalApiPanelProvider')
  20. return context
  21. }