Skip to content

Commit 0f3ad46

Browse files
committed
fix: useAppVisible hook
1 parent 7757e0e commit 0f3ad46

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/App.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@ import React, { useRef, useState } from "react";
22

33
const useAppVisible = () => {
44
const [visible, setVisible] = useState(logseq.isMainUIVisible);
5-
logseq.on("ui:visible:changed", async ({ visible }) => {
6-
setVisible(visible);
7-
});
5+
React.useEffect(() => {
6+
const eventName = "ui:visible:changed";
7+
const handler = async ({ visible }: any) => {
8+
setVisible(visible);
9+
};
10+
logseq.on(eventName, handler);
11+
return () => {
12+
logseq.off(eventName, handler);
13+
};
14+
}, []);
815
return visible;
916
};
1017

0 commit comments

Comments
 (0)