Skip to content

Commit

Permalink
Optimize: component rendering with useCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
amasin76 committed Sep 1, 2023
1 parent 4c7fdb1 commit 4632da4
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/pages/popup/components/Checker/TaskList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// TaskList.tsx
import React, { useState, useEffect } from "react";
import { useState, useEffect, useCallback } from "react";
import { useData } from "../../context/DataContext";

interface TaskListProps {
Expand All @@ -10,7 +9,7 @@ export const TaskList: React.FC<TaskListProps> = ({ onCheck }) => {
const { tasks, checkedTasks, setCheckedTasks, runningTasks, setRunningTasks, setTaskStatus } = useData();
const [finishedTasks, setFinishedTasks] = useState<string[]>([]);

const handleFinishedTasks = (request: any) => {
const handleFinishedTasks = useCallback((request: any) => {
if (request.message === "task_finished") {
const { taskId, taskStatus } = request;

Expand All @@ -28,7 +27,7 @@ export const TaskList: React.FC<TaskListProps> = ({ onCheck }) => {
setFinishedTasks((prevFinishedTasks) => prevFinishedTasks.filter((id) => id !== taskId));
}, 2000);
}
};
}, []);

useEffect(() => {
chrome.runtime.onMessage.addListener(handleFinishedTasks);
Expand Down

0 comments on commit 4632da4

Please sign in to comment.