Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🔨 Ensure preferences context is present (#931)

Luke Vella3f6a5603b353
diff --git a/apps/web/src/contexts/preferences.tsx b/apps/web/src/contexts/preferences.tsx
index e87eac79a..8629a11b4 100644
--- a/apps/web/src/contexts/preferences.tsx
+++ b/apps/web/src/contexts/preferences.tsx
@@ -2,6 +2,8 @@ import { TimeFormat } from "@rallly/database";
import React from "react";
import { useSetState } from "react-use";
+import { useRequiredContext } from "@/components/use-required-context";
+
type Preferences = {
timeZone?: string | null;
locale?: string | null;
@@ -14,10 +16,9 @@ type PreferencesContextValue = {
updatePreferences: (preferences: Partial<Preferences>) => void;
};
-const PreferencesContext = React.createContext<PreferencesContextValue>({
- preferences: {},
- updatePreferences: () => {},
-});
+const PreferencesContext = React.createContext<PreferencesContextValue | null>(
+ null,
+);
export const PreferencesProvider = ({
children,
@@ -46,5 +47,5 @@ export const PreferencesProvider = ({
};
export const usePreferences = () => {
- return React.useContext(PreferencesContext);
+ return useRequiredContext(PreferencesContext);
};