UNPKG

@yamada-ui/react

Version:

React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion

29 lines (25 loc) 887 B
"use client"; import * as React from "react"; import { use } from "react"; //#region src/utils/context.ts function getErrorMessage(hookName, ContextName) { return `${hookName} returned \`undefined\`. Seems you forgot to wrap component within ${ContextName}`; } function createContext$1({ name = "Context", defaultValue, errorMessage, hookName = `use${name}`, strict = true } = {}) { const Context = React.createContext(defaultValue); Context.displayName = name; const useContext$1 = () => { const context = use(Context); if (!context && strict) { const error = new Error(errorMessage ?? getErrorMessage(hookName, name)); error.name = "ContextError"; Error.captureStackTrace(error, useContext$1); throw error; } return context; }; return [Context, useContext$1]; } //#endregion export { createContext$1 as createContext }; //# sourceMappingURL=context.js.map