UNPKG

@awsui/components-react

Version:

On July 19th, 2022, we launched [Cloudscape Design System](https://cloudscape.design). Cloudscape is an evolution of AWS-UI. It consists of user interface guidelines, front-end components, design resources, and development tools for building intuitive, en

33 lines 1.61 kB
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { useEffect, useMemo } from 'react'; import { parseCountValue } from '../../internal/analytics/utils/parse-count-text'; import { useTableComponentsContext } from '../../internal/context/table-component-context'; /** * Custom hook that integrates table counter values with table component context. * * The extracted count value is automatically synchronized with the table header * component through the table context, updating the countText property. */ export const useTableIntegration = (countText) => { const tableComponentContext = useTableComponentsContext(); const countValue = useMemo(() => { if (typeof countText === 'string') { return parseCountValue(countText); } else { return undefined; } }, [countText]); useEffect(() => { var _a; if (((_a = tableComponentContext === null || tableComponentContext === void 0 ? void 0 : tableComponentContext.headerRef) === null || _a === void 0 ? void 0 : _a.current) && countValue !== undefined) { tableComponentContext.headerRef.current.totalCount = countValue; return () => { var _a; (_a = tableComponentContext.headerRef.current) === null || _a === void 0 ? true : delete _a.totalCount; }; } }, [tableComponentContext === null || tableComponentContext === void 0 ? void 0 : tableComponentContext.headerRef, countValue]); }; //# sourceMappingURL=use-table-integration.js.map