From 8597e59020d000925df3bb837f2b3eb7f532f4b1 Mon Sep 17 00:00:00 2001 From: AlekseyManetov Date: Thu, 14 Nov 2024 15:06:32 +0100 Subject: [PATCH] [useTableState]: fix error when params not provided --- uui-core/src/hooks/useTableState/useTableState.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/uui-core/src/hooks/useTableState/useTableState.ts b/uui-core/src/hooks/useTableState/useTableState.ts index 7a544e89fe..2210ae55a3 100644 --- a/uui-core/src/hooks/useTableState/useTableState.ts +++ b/uui-core/src/hooks/useTableState/useTableState.ts @@ -196,26 +196,26 @@ export interface UseTableStateHookParams, TViewSta extends UseTableStateHookBaseParams, Partial>> {} export const useTableState = , TViewState = any> -(params?: UseTableStateHookParams): ITableState => { +(params: UseTableStateHookParams = {}): ITableState => { const context = useUuiContext(); - const externalValue = useRef(params.value); + const externalValue = useRef(params?.value); const [tableStateValue, setTableStateValue] = useState>(() => { const value = getValueFromUrl(context.uuiRouter.getCurrentLink().query); - const activePreset = params.initialPresets?.find((p: ITablePreset) => p.id === value.presetId); + const activePreset = params?.initialPresets?.find((p: ITablePreset) => p.id === value.presetId); const filtersConfig = normalizeFilterConfig(activePreset?.filtersConfig, value.filter, params?.filters); return { ...value, filtersConfig, topIndex: 0, - visibleCount: params.initialVisibleCount || 40, + visibleCount: params?.initialVisibleCount || 40, }; }); const getTableStateValue = () => { if (params?.onValueChange) { - return params.value; + return params?.value; } const valueFromUrl = getValueFromUrl(context.uuiRouter.getCurrentLink().query); @@ -241,11 +241,11 @@ export const useTableState = , TViewState = any> } }; const onValueChange = useCallback((update: (val: DataTableState) => DataTableState) => { - if (params.onValueChange) { + if (params?.onValueChange) { const newValue = update(externalValue.current); const resultValue = normalizeTableStateValue(newValue, externalValue.current, params.filters); externalValue.current = resultValue; - params.onValueChange(resultValue); + params?.onValueChange(resultValue); } else { setTableStateValue((currentValue) => { const newValue = update(currentValue);