Skip to content

Commit

Permalink
Merge pull request #29 from deriv-com/shasyan/fix-active-tab-on-reload
Browse files Browse the repository at this point in the history
fix: added useEffect for activeTab in Tabs component
  • Loading branch information
shayan-deriv authored Jan 29, 2024
2 parents ee2493a + 6c80b9f commit 7e2099c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/components/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactElement, useState } from 'react';
import React, { ReactElement, useEffect, useState } from 'react';
import TabTitle, { TabTitleProps } from './TabTitle';
import clsx from 'clsx';
import './Tabs.scss';
Expand All @@ -15,6 +15,12 @@ type TabsProps = {
const Tabs = ({ children, activeTab, wrapperClassName, className, variant = 'primary', onChange }: TabsProps): JSX.Element => {
const [selectedTab, setSelectedTab] = useState(activeTab || children[0].props.title);

useEffect(() => {
if (activeTab) {
setSelectedTab(activeTab);
}
}, [activeTab]);

return (
<div className={wrapperClassName}>
<div className={clsx(`derivs-${variant + '-'}tabs`, className)}>
Expand Down

0 comments on commit 7e2099c

Please sign in to comment.