Last active
October 9, 2021 22:11
-
-
Save fernandodof/f0ab957a29f7ffb15009c894e48ff6e4 to your computer and use it in GitHub Desktop.
React tabs
This file contains 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, { useCallback } from 'react'; | |
import styles from './tabTitle.module.css'; | |
export type Props = { | |
title: string; | |
index: number; | |
setSelectedTab: (index: number) => void; | |
isActive?: boolean; | |
}; | |
const TabTitle = (props: Props): JSX.Element => { | |
const { title, setSelectedTab, index, isActive } = props; | |
const handleOnClick = useCallback(() => { | |
setSelectedTab(index); | |
}, [setSelectedTab, index]); | |
return ( | |
<li className={`${styles.title} ${isActive ? 'active' : ''}`}> | |
<button onClick={handleOnClick}>{title}</button> | |
</li> | |
); | |
}; | |
export default TabTitle; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment