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:
@@ -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 }}>
|
||||
|
||||
Reference in New Issue
Block a user