Created
May 23, 2022 10:57
-
-
Save alpavlove/bfd7ec9399d03a404cea00c0266ed07f to your computer and use it in GitHub Desktop.
Basic Tabs component - Tabs component with logic Tabs.tsx
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 React, { ReactElement, useState } from "react" | |
import TabTitle from "./TabTitle" | |
type Props = { | |
children: ReactElement[] | |
} | |
const Tabs: React.FC<Props> = ({ children }) => { | |
const [selectedTab, setSelectedTab] = useState(0) | |
return ( | |
<div> | |
<ul> | |
{children.map((item, index) => ( | |
<TabTitle | |
key={index} | |
title={item.props.title} | |
index={index} | |
setSelectedTab={setSelectedTab} | |
/> | |
))} | |
</ul> | |
{children[selectedTab]} | |
</div> | |
) | |
} | |
export default Tabs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment