Skip to content

Commit

Permalink
add useEffect for selected tab
Browse files Browse the repository at this point in the history
  • Loading branch information
raejohanek committed Jan 22, 2025
1 parent 0dd6abc commit 2cd980c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/components/common/TabWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ClassNameMap, createStyles, withStyles } from '@mui/styles';
import React from 'react';
import React, { useEffect } from 'react';
import { connect } from 'react-redux';
import Tabs from '@mui/material/Tabs';
import { TabClasses } from '@mui/material/Tab/tabClasses';
import Tab from '@mui/material/Tab';
import { Link } from 'react-router-dom';
import { Link, useLocation } from 'react-router-dom';
import HelpContainer from 'components/help/HelpContainer';
import history from 'modules/hist';
import { CustomTheme } from '@mui/material/styles';
Expand Down Expand Up @@ -64,9 +64,13 @@ type TabWrapperProps = {

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

const locationSplit = history.location.pathname.split('/');
const selectedTab = `/${locationSplit[1] || 'datasets'}`;
useEffect(() => {
const locationSplit = history.location.pathname.split('/');
setSelectedTab(`/${locationSplit[1] || 'datasets'}`);
}, [location]);

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

0 comments on commit 2cd980c

Please sign in to comment.