Skip to content

Commit

Permalink
refactor: contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrobertbrooks committed Jul 30, 2024
1 parent 58e2f8a commit 945ca12
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/contexts/EventsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <EventsProvider />"
);
}
return context;
};
11 changes: 9 additions & 2 deletions src/contexts/ParamsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ParamsProvider />"
);
}
return context;
};

0 comments on commit 945ca12

Please sign in to comment.