Created
November 14, 2021 11:09
-
-
Save choyan/46bf4c3000f59f13b6fe205da00b427f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState } from "react"; | |
import { Tab, Tabs, TabList, TabPanel } from "react-tabs"; | |
import "react-tabs/style/react-tabs.css"; | |
export default function App() { | |
const [tabIndex, setTabIndex] = useState(0); | |
const goToTabOne = () => { | |
setTabIndex(0); | |
}; | |
return ( | |
<Tabs selectedIndex={tabIndex} onSelect={(index) => setTabIndex(index)}> | |
<TabList> | |
<Tab>Title 1</Tab> | |
<Tab>Title 2</Tab> | |
<Tab>Title 3</Tab> | |
<Tab>Title 4</Tab> | |
</TabList> | |
<TabPanel> | |
<h2>Any content 1</h2> | |
</TabPanel> | |
<TabPanel> | |
<h2>Any content 2</h2> | |
</TabPanel> | |
<TabPanel> | |
<h2>Any content 3</h2> | |
</TabPanel> | |
<TabPanel> | |
<h2>Any content 4</h2> | |
<button onClick={goToTabOne}>Go to tab 1</button> | |
</TabPanel> | |
</Tabs> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment