Skip to content

Instantly share code, notes, and snippets.

@fernandodof
Last active October 9, 2021 22:11
Show Gist options
  • Save fernandodof/f0ab957a29f7ffb15009c894e48ff6e4 to your computer and use it in GitHub Desktop.
Save fernandodof/f0ab957a29f7ffb15009c894e48ff6e4 to your computer and use it in GitHub Desktop.
React tabs
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