init
This commit is contained in:
27
src/contexts/DialogContext.tsx
Normal file
27
src/contexts/DialogContext.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import React, { createContext, useContext } from 'react'
|
||||
|
||||
const DialogContext = createContext<HTMLElement | null>(null)
|
||||
|
||||
export function DialogProvider({
|
||||
children,
|
||||
container,
|
||||
}: {
|
||||
children: React.ReactNode
|
||||
container: HTMLElement | null
|
||||
}) {
|
||||
return (
|
||||
<DialogContext.Provider value={container}>
|
||||
{children}
|
||||
</DialogContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export function useDialogContainer() {
|
||||
const context = useContext(DialogContext)
|
||||
if (!context) {
|
||||
throw new Error(
|
||||
'useDialogContainer must be used within a DialogContainerProvider',
|
||||
)
|
||||
}
|
||||
return context
|
||||
}
|
||||
Reference in New Issue
Block a user