feat: add useEffect to PreferencesContext for automatic fetching of user preferences on component mount
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import React, { createContext, useContext, useState } from "react";
|
||||
import React, { createContext, useContext, useState, useEffect } from "react";
|
||||
import { ERROR_CODES } from "../constants/errorCodes";
|
||||
import { AppError } from "../utils/errors";
|
||||
import type { UserPreferences } from "@/types/preferences";
|
||||
@@ -45,6 +45,10 @@ export function PreferencesProvider({
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchPreferences();
|
||||
}, []);
|
||||
|
||||
const updatePreferences = async (newPreferences: Partial<UserPreferences>) => {
|
||||
try {
|
||||
const response = await fetch("/api/preferences", {
|
||||
|
||||
Reference in New Issue
Block a user