@appbuckets/react-ui
Version:
Just Another React UI Framework
38 lines (35 loc) • 868 B
JavaScript
import { __read } from 'tslib';
import * as React from 'react';
/**
* Use this hook to get automatically the active index
* of a Tab Component.
* Additionally function to force change will be returned
*
* @param initialValue
*/
function useTabsChange(initialValue) {
// ----
// Internal State
// ----
var _a = __read(
React.useState(
initialValue !== null && initialValue !== void 0 ? initialValue : 0
),
2
),
activeIndex = _a[0],
setActiveIndex = _a[1];
// ----
// Handler
// ----
var handleTabsChange = React.useCallback(function (e, props) {
var _a;
/** Set the new ActiveIndex */
setActiveIndex((_a = props.activeIndex) !== null && _a !== void 0 ? _a : 0);
}, []);
// ----
// Hook Return
// ----
return [activeIndex, handleTabsChange, setActiveIndex];
}
export { useTabsChange };