1.0.0 • Published 3 years ago

@banghook/use-tabs v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Usage

import useInput from "@banghook/use-tabs"

const content = [
    {
        tab: "Section 1",
        content: "I am the content of the Section 1"
    },
    {
        tab: "Section 2",
        content: "I am the content of the Section 2"
    }
];

function App() {
    const { currentItem, changeItem } = useTabs(0, content);
    return (
        <div className="App">
            {content.map((section, index) => (
                <button
                    onClick={() => {
                        changeItem(index);
                    }}
                >
                    {section.tab}
                </button>
            ))}
            <div>{currentItem.content}</div>
        </div>
    );
}