Skip to content

Commit 2cd980c

Browse files
committed
add useEffect for selected tab
1 parent 0dd6abc commit 2cd980c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/components/common/TabWrapper.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { ClassNameMap, createStyles, withStyles } from '@mui/styles';
2-
import React from 'react';
2+
import React, { useEffect } from 'react';
33
import { connect } from 'react-redux';
44
import Tabs from '@mui/material/Tabs';
55
import { TabClasses } from '@mui/material/Tab/tabClasses';
66
import Tab from '@mui/material/Tab';
7-
import { Link } from 'react-router-dom';
7+
import { Link, useLocation } from 'react-router-dom';
88
import HelpContainer from 'components/help/HelpContainer';
99
import history from 'modules/hist';
1010
import { CustomTheme } from '@mui/material/styles';
@@ -64,9 +64,13 @@ type TabWrapperProps = {
6464

6565
function TabWrapper(props: TabWrapperProps) {
6666
const { classes, routes, snapshotAccessRequests } = props;
67+
const [selectedTab, setSelectedTab] = React.useState<string>('datasets');
68+
const location = useLocation();
6769

68-
const locationSplit = history.location.pathname.split('/');
69-
const selectedTab = `/${locationSplit[1] || 'datasets'}`;
70+
useEffect(() => {
71+
const locationSplit = history.location.pathname.split('/');
72+
setSelectedTab(`/${locationSplit[1] || 'datasets'}`);
73+
}, [location]);
7074

7175
const tabConfigs: Array<ITabConfig> = [
7276
{ label: 'Datasets', path: '/datasets' },

0 commit comments

Comments
 (0)