Skip to content

Commit

Permalink
fix: added useEffect for activeTab in Tabs component
Browse files Browse the repository at this point in the history
  • Loading branch information
shayan-deriv committed Jan 29, 2024
1 parent 697d507 commit 6c80b9f
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 6c80b9f

Please sign in to comment.