init
This commit is contained in:
3
src/utils/parseError.ts
Normal file
3
src/utils/parseError.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export function parseError(error: unknown): Error {
|
||||
return error instanceof Error ? error : new Error(JSON.stringify(error));
|
||||
}
|
||||
13
src/utils/useRequiredContext.ts
Normal file
13
src/utils/useRequiredContext.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { type Context, useContext } from "solid-js";
|
||||
|
||||
export const useRequiredContext = <T>(context: Context<T | undefined>): T => {
|
||||
const getContext = useContext(context);
|
||||
|
||||
if (getContext === undefined) {
|
||||
throw new Error(
|
||||
`${context.constructor.name} must be used within a provider instance`,
|
||||
);
|
||||
}
|
||||
|
||||
return getContext;
|
||||
};
|
||||
Reference in New Issue
Block a user