Skip to content

Commit 694d03b

Browse files
committed
fix bugs
1 parent 6ff8a97 commit 694d03b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/pages/ToolsLayout.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from 'react';
1+
import React, { useCallback, useEffect, useState } from 'react';
22
import {
33
ClockCircleOutlined,
44
DiffOutlined,
@@ -70,16 +70,17 @@ const ToolsLayout: React.FC = () => {
7070

7171
const navigate = useNavigate();
7272
const location = useLocation();
73-
const [selectedKey, setSelectedKey] = useState<string>(getCurrentTabKey());
74-
73+
7574
// get tab key from url path
76-
function getCurrentTabKey() {
75+
const getCurrentTabKey = useCallback(() => {
7776
const pathParts = location.pathname.split('/');
7877
const lastPart = pathParts[pathParts.length - 1];
7978
// check if lastPart is in topItems
8079
const validKeys = topItems.map(item => item!.key);
8180
return validKeys.includes(lastPart) ? lastPart : 'timestamp';
82-
}
81+
}, [location]);
82+
83+
const [selectedKey, setSelectedKey] = useState<string>(getCurrentTabKey());
8384

8485
useEffect(() => {
8586
setSelectedKey(getCurrentTabKey());

0 commit comments

Comments
 (0)