feat(webapp): import resource UI

This commit is contained in:
Ahmed Bouhuolia
2024-03-19 03:57:57 +02:00
parent 1ba26a3b85
commit ff5730d8a7
37 changed files with 1470 additions and 12 deletions

View File

@@ -0,0 +1,25 @@
import React, { createContext, useContext } from 'react';
export function createSafeContext<ContextValue>(errorMessage: string) {
const Context = createContext<ContextValue | null>(null);
const useSafeContext = () => {
const ctx = useContext(Context);
if (ctx === null) {
throw new Error(errorMessage);
}
return ctx;
};
const Provider = ({
children,
value,
}: {
value: ContextValue;
children: React.ReactNode;
}) => <Context.Provider value={value}>{children}</Context.Provider>;
return [Provider, useSafeContext] as const;
}