UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

42 lines 1.09 kB
import "core-js/modules/es.string.replace.js"; import { useCallback } from 'react'; import { useTranslation } from '../../hooks'; import { useSharedState } from '../../../../shared/helpers/useSharedState'; export default function useArrayLimit(path) { const sharedState = useSharedState(path + '-iterate-limit'); const { set, update, extend, data } = sharedState || {}; const { limit, total, show } = data || {}; const setLimitProps = useCallback(props => { if (props.total !== total) { update(props); } else { set(props); } }, [set, total, update]); const setShowStatus = useCallback(show => { extend({ show }); }, [extend]); const hasReachedLimit = typeof limit === 'number' && total >= limit; const { itemsLimitReached } = useTranslation().IteratePushContainer; const error = show ? new Error(itemsLimitReached.replace('{limit}', String(limit))) : undefined; return { setShowStatus, setLimitProps, error, hasReachedLimit }; } //# sourceMappingURL=useArrayLimit.js.map