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