Created
June 24, 2020 18:26
-
-
Save gavinsharp/2710b4b07401e7ae4c5b012cdd3ec332 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
// Assuming: | |
// <Tabs> | |
// <Tab title="">...</Tab> | |
// <Tab title="">...</Tab> | |
// <Tab title="">...</Tab> | |
// </Tabs> | |
function Tabs({ children }) { | |
const tabs = React.Children.toArray(children); | |
const [selectedTabTitle, setSelectedTabTitle] = useState(tabs[0].props.title); | |
const selectedTab = tabs.find(tab => tab.props.title === selectedTabTitle); | |
return ( | |
<TabsContainer> | |
<TabBar> | |
{tabs.map(tab => <ClickableTab onClick={() => setSelectedTabTitle(tab.props.title)} ... />)} | |
</TabBar> | |
<CurrentTab> | |
{selectedTab} | |
</CurrentTab> | |
</TabsContainer> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment