Skip to content

Commit 3b73285

Browse files
authored
fix: delcare the useEffect before return (#808)
1 parent 219b937 commit 3b73285

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/workbench/sidebar/explore/folderTree.tsx

+19-19
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,6 @@ const FolderTree: React.FunctionComponent<IFolderTreeProps> = (props) => {
9090
current,
9191
} = folderTree;
9292

93-
const handleAddRootFolder = () => {
94-
createTreeNode?.('RootFolder');
95-
};
96-
97-
const welcomePage = (
98-
<div data-content={panel.id}>
99-
{entry ? (
100-
<>{entry}</>
101-
) : (
102-
<div style={{ padding: '10px 5px' }}>
103-
you have not yet opened a folder
104-
<Button onClick={handleAddRootFolder}>Add Folder</Button>
105-
</div>
106-
)}
107-
</div>
108-
);
109-
110-
if (!data.length) return welcomePage;
111-
11293
const inputRef = useRef<HTMLInputElement>(null);
11394
// tree context view
11495
const contextMenu = useRef<ReturnType<typeof useContextMenu>>();
@@ -221,6 +202,10 @@ const FolderTree: React.FunctionComponent<IFolderTreeProps> = (props) => {
221202
onDropTree?.(source, target);
222203
};
223204

205+
const handleAddRootFolder = () => {
206+
createTreeNode?.('RootFolder');
207+
};
208+
224209
useEffect(() => {
225210
if (folderPanelContextMenu.length > 0) {
226211
contextMenu.current = initContextMenu();
@@ -230,6 +215,21 @@ const FolderTree: React.FunctionComponent<IFolderTreeProps> = (props) => {
230215
};
231216
}, [data.length]);
232217

218+
const welcomePage = (
219+
<div data-content={panel.id}>
220+
{entry ? (
221+
<>{entry}</>
222+
) : (
223+
<div style={{ padding: '10px 5px' }}>
224+
you have not yet opened a folder
225+
<Button onClick={handleAddRootFolder}>Add Folder</Button>
226+
</div>
227+
)}
228+
</div>
229+
);
230+
231+
if (!data.length) return welcomePage;
232+
233233
return (
234234
<Scrollable noScrollX isShowShadow>
235235
<div data-content={panel.id} style={{ height: '100%' }}>

0 commit comments

Comments
 (0)