1.0.3 • Published 2 years ago

use-collapsible-hook v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

use-collapsible-hook

A React.js hook for creating collapsible content.

Installation

npm install use-collapsible-hook

Usage

import React from 'react';
import useCollapsible from 'use-collapsible-hook';

const App = () => {
    const {
        ref,
        isCollapsed,
        height,
        onToggle,
    } = useCollapsible(true);

    return (
        <div>
            <button onClick={onToggle}>Toggle</button>

            <div ref={ref} style={{
                height: isCollapsed ? 0 : height
            }}>
                <p>Some collapsible content</p>
                <p>More collapsible content</p>
                <p>Even more collapsible content</p>
            </div>
        </div>
    );
};