UNPKG

@appbuckets/react-ui

Version:
32 lines (29 loc) 787 B
import { __read } from 'tslib'; import * as React from 'react'; /** * Use this hook to get automatically the open value * and the handler function to attach to collapsable element. * Additionally function to force change will be returned * * @param initialState */ function useCollapsableState(initialState) { // ---- // Internal State // ---- var _a = __read(React.useState(initialState), 2), currentState = _a[0], setCurrentState = _a[1]; // ---- // Handler // ---- var handleCollapsableStateChange = React.useCallback(function (newState) { /** Update the state */ setCurrentState(newState); }, []); // ---- // Hook Return // ---- return [currentState, handleCollapsableStateChange, setCurrentState]; } export { useCollapsableState };