feat: add useEffect to PreferencesContext for automatic fetching of user preferences on component mount

This commit is contained in:
Julien Froidefond
2025-10-17 11:56:54 +02:00
parent 482bd9b0d2
commit 096bc78868

View File

@@ -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", {