From 945ca121a431afbc82332e493671cf0857c0de66 Mon Sep 17 00:00:00 2001 From: Colin Brooks Date: Tue, 30 Jul 2024 08:42:28 -0400 Subject: [PATCH] refactor: contexts --- src/contexts/EventsContext.tsx | 11 +++++++++-- src/contexts/ParamsContext.tsx | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/contexts/EventsContext.tsx b/src/contexts/EventsContext.tsx index be6958e..1f4066d 100644 --- a/src/contexts/EventsContext.tsx +++ b/src/contexts/EventsContext.tsx @@ -77,5 +77,12 @@ export const EventsProvider = ({ ); }; -export const useEventsContext = (): EventsContextValue => - useContext(EventsContext); +export const useEventsContext = (): EventsContextValue => { + const context = useContext(EventsContext); + if (!context) { + throw new Error( + "useEventsContext must be used within a " + ); + } + return context; +}; diff --git a/src/contexts/ParamsContext.tsx b/src/contexts/ParamsContext.tsx index 55db41e..aa89edd 100644 --- a/src/contexts/ParamsContext.tsx +++ b/src/contexts/ParamsContext.tsx @@ -36,5 +36,12 @@ export const ParamsProvider = ({ ); }; -export const useParamsContext = (): ParamsContextValue => - useContext(ParamsContext); +export const useParamsContext = (): ParamsContextValue => { + const context = useContext(ParamsContext); + if (!context) { + throw new Error( + "useParamsContext must be used within a " + ); + } + return context; +};