import { createContext, FC, useCallback, useContext, useState } from 'react' const GlobalAlertsContext = createContext( undefined ) export const GlobalAlertsProvider: FC = ({ children }) => { const [globalAlertsContainer, setGlobalAlertsContainer] = useState(null) const handleGlobalAlertsContainer = useCallback( (node: HTMLDivElement | null) => { setGlobalAlertsContainer(node) }, [] ) return (
{children} ) } export const useGlobalAlertsContainer = () => { const context = useContext(GlobalAlertsContext) if (context === undefined) { throw new Error( 'useGlobalAlertsContainer is only available inside GlobalAlertsProvider' ) } return context }