Skip to content

Instantly share code, notes, and snippets.

@choyan
Created November 14, 2021 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save choyan/46bf4c3000f59f13b6fe205da00b427f to your computer and use it in GitHub Desktop.
Save choyan/46bf4c3000f59f13b6fe205da00b427f to your computer and use it in GitHub Desktop.
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