Skip to content

Commit 68d9e53

Browse files
authored
Refactor DiscourseContextOverlay to optimize tag and uid handling (#381)
- Replaced direct tag and uid handling with useMemo for improved performance. - Updated getOverlayInfo call to utilize the new tag logic, enhancing clarity. - Adjusted dependencies in useCallback to ensure accurate state management.
1 parent b776e72 commit 68d9e53

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

apps/roam/src/components/DiscourseContextOverlay.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,14 @@ const DiscourseContextOverlay = ({
6767
id,
6868
uid,
6969
}: DiscourseContextOverlayProps) => {
70-
const newTag = tag ?? (uid ? (getPageTitleByPageUid(uid) ?? "") : "");
71-
const tagUid = uid || getPageUidByPageTitle(newTag);
70+
const tagUid = useMemo(() => uid ?? getPageUidByPageTitle(tag), [uid, tag]);
7271
const [loading, setLoading] = useState(true);
7372
const [results, setResults] = useState<DiscourseData["results"]>([]);
7473
const [refs, setRefs] = useState(0);
7574
const [score, setScore] = useState<number | string>(0);
7675
const getInfo = useCallback(
7776
() =>
78-
getOverlayInfo(newTag)
77+
getOverlayInfo(tag ?? (uid ? (getPageTitleByPageUid(uid) ?? "") : ""))
7978
.then(({ refs, results }) => {
8079
const discourseNode = findDiscourseNode(tagUid);
8180
if (discourseNode) {
@@ -95,7 +94,7 @@ const DiscourseContextOverlay = ({
9594
}
9695
})
9796
.finally(() => setLoading(false)),
98-
[tag, setResults, setLoading, setRefs, setScore],
97+
[tag, uid, tagUid, setResults, setLoading, setRefs, setScore],
9998
);
10099
const refresh = useCallback(() => {
101100
setLoading(true);

0 commit comments

Comments
 (0)