Skip to content

Commit

Permalink
memoize the context state
Browse files Browse the repository at this point in the history
Signed-off-by: Scott J Dickerson <sdickers@redhat.com>
  • Loading branch information
sjd78 committed Jun 20, 2024
1 parent ad3f2fb commit ff32717
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions client/src/app/components/task-manager/TaskManagerContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useFetchTaskQueue } from "@app/queries/tasks";
import React, { useContext, useState } from "react";
import React, { useContext, useMemo, useState } from "react";

interface TaskManagerContextProps {
/** Count of the currently "queued" Tasks */
Expand Down Expand Up @@ -31,14 +31,17 @@ export const TaskManagerProvider: React.FC<{ children: React.ReactNode }> = ({
const { taskQueue } = useFetchTaskQueue();
const [isExpanded, setIsExpanded] = useState(false);

const contextValue = useMemo(
() => ({
queuedCount: taskQueue.total,
isExpanded,
setIsExpanded,
}),
[taskQueue.total, isExpanded, setIsExpanded]
);

return (
<TaskManagerContext.Provider
value={{
queuedCount: taskQueue.total,
isExpanded,
setIsExpanded,
}}
>
<TaskManagerContext.Provider value={contextValue}>
{children}
</TaskManagerContext.Provider>
);
Expand Down

0 comments on commit ff32717

Please sign in to comment.