SchemaGraphContext.tsx 832 B

1234567891011121314151617181920212223242526
  1. import { Edge } from '@xyflow/react'
  2. import { createContext, useContext, type ReactNode } from 'react'
  3. export type SchemaGraphContextType = {
  4. isDownloading: boolean
  5. selectedEdge: Edge | undefined
  6. onEditColumn: (tableId: number, columnId: string) => void
  7. onEditTable: (tableId: number) => void
  8. }
  9. export const SchemaGraphContext = createContext<SchemaGraphContextType | null>(null)
  10. export const SchemaGraphContextProvider = ({
  11. children,
  12. value,
  13. }: {
  14. children: ReactNode
  15. value: SchemaGraphContextType
  16. }) => <SchemaGraphContext.Provider value={value}>{children}</SchemaGraphContext.Provider>
  17. export const useSchemaGraphContext = () => {
  18. const context = useContext(SchemaGraphContext)
  19. if (!context)
  20. throw new Error('useSchemaGraphContext must be used inside a <SchemaGraphContextProvider>')
  21. return context
  22. }