From d57292d123f639362c4be1c61729460fa9cc2e8f Mon Sep 17 00:00:00 2001
From: sowgro <tpoke.ferrari@gmail.com>
Date: Tue, 5 Nov 2024 13:05:52 -0500
Subject: Fix infinite loop

---
 extension/src/Body.tsx | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

(limited to 'extension/src/Body.tsx')

diff --git a/extension/src/Body.tsx b/extension/src/Body.tsx
index b2f8495..ee38cf1 100644
--- a/extension/src/Body.tsx
+++ b/extension/src/Body.tsx
@@ -1,4 +1,4 @@
-import React, {useState} from "react";
+import React, {useEffect, useState} from "react";
 import SettingsEditor from "./SettingsEditor.tsx";
 import Folder from "./Folder.tsx";
 import imageUrl from "./assets/settings.svg"
@@ -24,21 +24,18 @@ function Body() {
     const [rootFolder, setRootFolder] = useState('1')
     const [bookmarkTree, setBookmarkTree] = useState<BookmarkTreeNode[]>([])
     const [ogBookmarkTree, setOgBookmarkTree] = useState<BookmarkTreeNode[] | null>([])
-
-    browser.bookmarks.getSubTree(rootFolder).then(t => {
-        console.log(t);
-        if (t != bookmarkTree) {
-            setBookmarkTree(t);
-        }
-        console.log(bookmarkTree == t)
-    });
-
-    if (ogBookmarkTree?.length == 0) {
+    useEffect(() => {
         browser.bookmarks.getTree().then(t => {
             setOgBookmarkTree(t);
         })
-    }
+    }, [])
+    useEffect(() => {
+        browser.bookmarks.getSubTree(rootFolder).then(t => {
+            setBookmarkTree(t);
+        });
+    }, [rootFolder]);
 
+    console.log("Body re-render")
     return (
         <BookmarkTree.Provider value={{bookmarkTree, setBookmarkTree}}>
         <RootFolder.Provider value={{rootFolder, setRootFolder}}>
-- 
cgit v1.2.3

