fix(sessions): stabilize setAllSessions to prevent polling loop

Wrap setAllSessions in useCallback so it has a stable reference.
This breaks the infinite re-render loop that was causing 4-10
requests per second to /users/me/sessions.
This commit is contained in:
Fusion
2026-05-20 13:41:24 +02:00
parent 9d27cd9fe8
commit b4a7627718
+3 -3
View File
@@ -1,4 +1,4 @@
import { createContext, useContext, useState, type ReactNode } from "react";
import { createContext, useCallback, useContext, useState, type ReactNode } from "react";
export interface Session {
id: string;
@@ -24,9 +24,9 @@ const SessionsContext = createContext<SessionsContextType | undefined>(undefined
export const SessionsProvider = ({ children }: { children: ReactNode }) => {
const [sessions, setSessions] = useState<Session[]>([]);
const setAllSessions = (newSessions: Session[]) => {
const setAllSessions = useCallback((newSessions: Session[]) => {
setSessions(newSessions);
};
}, []);
return (
<SessionsContext.Provider value={{ sessions, setAllSessions }}>