getStrictContext
sora-ui/lib-get-strict-contextFreeUtility
A hook that allows you to create a strict context.
Install it
npx shadcn@latest add https://ui.soralabs.io.vn/r/lib-get-strict-context.jsonSource
1import * as React from "react";23function getStrictContext<T>(4 name?: string5): readonly [6 ({7 value,8 children,9 }: {10 value: T;11 children?: React.ReactNode;12 }) => React.JSX.Element,13 () => T,14] {15 const Context = React.createContext<T | undefined>(undefined);1617 const Provider = ({18 value,19 children,20 }: {21 value: T;22 children?: React.ReactNode;23 }) => <Context.Provider value={value}>{children}</Context.Provider>;2425 const useSafeContext = () => {26 const ctx = React.useContext(Context);27 if (ctx === undefined) {28 throw new Error(`useContext must be used within ${name ?? "a Provider"}`);29 }30 return ctx;31 };3233 return [Provider, useSafeContext] as const;34}3536export { getStrictContext };
Files it writes
More from Sora UI
All 97 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Ease & Spring Tokenslib-ease | Sora UI | Utilities | Free | no deps | |
| Scroll Trigger Utilslib-scroll-trigger-utils | Sora UI | Utilities | Free | no deps |
