Get strict context
optics/get-strict-contextFreeUtility
Library utility: get-strict-context
See it running
Open the demo on optics
optics.agusmayol.com.ar/components/get-strict-contextInstall it
npx shadcn@latest add https://optics.agusmayol.com.ar/r/get-strict-context.jsonSource
1import * as React from "react";23function getStrictContext(name) {4 const Context = React.createContext(undefined);56 const Provider = ({ value, children }) => (7 <Context.Provider value={value}>{children}</Context.Provider>8 );910 const useSafeContext = () => {11 const ctx = React.useContext(Context);12 if (ctx === undefined) {13 throw new Error(`useContext must be used within ${name ?? "a Provider"}`);14 }15 return ctx;16 };1718 return [Provider, useSafeContext];19}2021export { getStrictContext };
Files it writes
More from optics
All 79 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Cursor Rule: Back Endcursor-rule-back-end | optics | Utilities | Free | no deps | |
| Cursor Rule: Bulk Processingcursor-rule-bulk-processing | optics | Utilities | Free | no deps | |
| Cursor Rule: Commits Conventioncursor-rule-commits-convention | optics | Utilities | Free | no deps | |
| Cursor Rule: Front Endcursor-rule-front-end | optics | Utilities | Free | no deps | |
| Cursor Rule: Generalcursor-rule-general | optics | Utilities | Free | no deps | |
| Cursor Rule: React Optimizationcursor-rule-react-optimization | optics | Utilities | Free | no deps | |
| Cursor Rule: Web Interface Guidelinescursor-rule-web-interface-guidelines | optics | Utilities | Free | no deps | |
| Use auto heightuse-auto-height | optics | Utilities | Free | no deps |
