From 5da292cb7236c8185d915fa2092e827717aa3697 Mon Sep 17 00:00:00 2001 From: MuelNova Date: Fri, 25 Oct 2024 12:32:24 +0800 Subject: [PATCH] :zap: Use useCallback for `getMediaInfo` --- src/components/Media/index.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/Media/index.tsx b/src/components/Media/index.tsx index 8707dd0..a27014b 100644 --- a/src/components/Media/index.tsx +++ b/src/components/Media/index.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from "react"; +import React, { useEffect, useState, useCallback } from "react"; import { useProvider } from "../../hooks"; import styles from "./Media.module.scss"; @@ -6,7 +6,7 @@ const Media = () => { const output = useProvider("glazewm"); const [mediaTitle, setMediaTitle] = useState(""); - const getMediaInfo = () => { + const getMediaInfo = useCallback(() => { for (const workspace of output?.allWorkspaces || []) { for (const window of workspace.children) { if (window.type === "window" && window.processName === "Spotify") { @@ -15,11 +15,11 @@ const Media = () => { } } return ""; - }; + }, [output]); useEffect(() => { setMediaTitle(getMediaInfo()); - }, [output]); + }, [getMediaInfo]); return ( mediaTitle !== "" && (