Skip to content

Commit

Permalink
fix: useAppVisible hook
Browse files Browse the repository at this point in the history
  • Loading branch information
pengx17 committed May 25, 2021
1 parent 7757e0e commit 0f3ad46
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ import React, { useRef, useState } from "react";

const useAppVisible = () => {
const [visible, setVisible] = useState(logseq.isMainUIVisible);
logseq.on("ui:visible:changed", async ({ visible }) => {
setVisible(visible);
});
React.useEffect(() => {
const eventName = "ui:visible:changed";
const handler = async ({ visible }: any) => {
setVisible(visible);
};
logseq.on(eventName, handler);
return () => {
logseq.off(eventName, handler);
};
}, []);
return visible;
};

Expand Down

0 comments on commit 0f3ad46

Please sign in to comment.