File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change 1- import React , { useEffect , useState } from 'react' ;
1+ import React , { useCallback , useEffect , useState } from 'react' ;
22import {
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 ( ) ) ;
You can’t perform that action at this time.
0 commit comments