2021-11-16 14:51:49 +00:00
|
|
|
import { createContext, PropsWithChildren, useContext } from 'react';
|
|
|
|
|
|
|
|
const Context = createContext<null | boolean>(null);
|
2022-09-20 18:14:24 +00:00
|
|
|
Context.displayName = 'WidgetContext';
|
2021-11-16 14:51:49 +00:00
|
|
|
|
|
|
|
export function useWidgetContext() {
|
|
|
|
const context = useContext(Context);
|
|
|
|
|
|
|
|
if (context == null) {
|
|
|
|
throw new Error('Should be inside a Widget component');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function Widget({ children }: PropsWithChildren<unknown>) {
|
|
|
|
return (
|
|
|
|
<Context.Provider value>
|
|
|
|
<div className="widget">{children}</div>
|
|
|
|
</Context.Provider>
|
|
|
|
);
|
|
|
|
}
|