@appbuckets/react-ui
Version:
Just Another React UI Framework
44 lines (41 loc) • 989 B
JavaScript
import { __read } from 'tslib';
import * as React from 'react';
/**
* Use this hook to get automatically the active indexes
* of an Accordion Component.
* Additionally function to force change will be returned
*
* @param initialValue
*/
function useAccordionSectionChange(initialValue) {
// ----
// Internal State
// ----
var _a = __read(
React.useState(
initialValue !== null && initialValue !== void 0 ? initialValue : []
),
2
),
activeIndexes = _a[0],
setActiveIndexes = _a[1];
// ----
// Handler
// ----
var handleAccordionSectionChange = React.useCallback(function (
action,
accordionProps
) {
var _a;
/** Update the ActiveIndexes */
setActiveIndexes(
(_a = accordionProps.activeIndexes) !== null && _a !== void 0 ? _a : []
);
},
[]);
// ----
// Hook Return
// ----
return [activeIndexes, handleAccordionSectionChange, setActiveIndexes];
}
export { useAccordionSectionChange };