mirror of
https://github.com/morten-olsen/refocus.dev.git
synced 2026-02-08 00:46:25 +01:00
init
This commit is contained in:
29
packages/sdk/src/widgets/context.tsx
Normal file
29
packages/sdk/src/widgets/context.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
import { TSchema } from '@sinclair/typebox';
|
||||
import { createContext, useState } from 'react';
|
||||
import { Widget } from './types';
|
||||
|
||||
type WidgetsContextValue = {
|
||||
widgets: Widget<TSchema>[];
|
||||
};
|
||||
|
||||
type WidgetsProviderProps = {
|
||||
children: React.ReactNode;
|
||||
widgets?: Widget<TSchema>[];
|
||||
};
|
||||
|
||||
const WidgetsContext = createContext<WidgetsContextValue | null>(null);
|
||||
|
||||
const WidgetsProvider: React.FC<WidgetsProviderProps> = ({
|
||||
children,
|
||||
widgets: initialWidgets,
|
||||
}) => {
|
||||
const [widgets] = useState<Widget<TSchema>[]>(initialWidgets || []);
|
||||
|
||||
return (
|
||||
<WidgetsContext.Provider value={{ widgets }}>
|
||||
{children}
|
||||
</WidgetsContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export { WidgetsContext, WidgetsProvider };
|
||||
Reference in New Issue
Block a user