mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
feat(webapp): import resource UI
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user