Skip to content

Commit

Permalink
⚡ Use useCallback for getMediaInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
MuelNova committed Oct 25, 2024
1 parent 8f4248f commit 5da292c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/components/Media/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { useEffect, useState } from "react";
import React, { useEffect, useState, useCallback } from "react";
import { useProvider } from "../../hooks";
import styles from "./Media.module.scss";

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") {
Expand All @@ -15,11 +15,11 @@ const Media = () => {
}
}
return "";
};
}, [output]);

useEffect(() => {
setMediaTitle(getMediaInfo());
}, [output]);
}, [getMediaInfo]);

return (
mediaTitle !== "" && (
Expand Down

0 comments on commit 5da292c

Please sign in to comment.