Skip to content

Commit

Permalink
fix(useList): support activeItemId in initialState prop
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaevAlexandr committed Aug 27, 2024
1 parent b953f18 commit 812f99b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/components/useList/hooks/useList.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable valid-jsdoc */
import React from 'react';

import type {ListState, UseListResult} from '../types';
import type {InitialListParsedState, UseListResult} from '../types';

import {useFlattenListItems} from './useFlattenListItems';
import {useListParsedState} from './useListParsedState';
Expand All @@ -10,7 +10,7 @@ import {useListState} from './useListState';
import type {UseListStateProps} from './useListState';

interface UseListProps<T> extends UseListParsedStateProps<T>, UseListStateProps {
controlledState?: Partial<ListState>;
controlledState?: Partial<InitialListParsedState>;
}

/**
Expand All @@ -30,16 +30,18 @@ export const useList = <T>({
defaultExpandedState,
});

const initValues = React.useMemo(() => {
const initValues: InitialListParsedState = React.useMemo(() => {
return {
expandedById: {...initialState.expandedById, ...initialValues?.expandedById},
selectedById: {...initialState.selectedById, ...initialValues?.selectedById},
disabledById: {...initialState.disabledById, ...initialValues?.disabledById},
activeItemId: initialValues?.activeItemId,
};
}, [
initialState.disabledById,
initialState.expandedById,
initialState.selectedById,
initialValues?.activeItemId,
initialValues?.disabledById,
initialValues?.expandedById,
initialValues?.selectedById,
Expand Down

0 comments on commit 812f99b

Please sign in to comment.