fix(striker-ui): avoid always refreshing items in list by making key consistent

main
Tsu-ba-me 11 months ago
parent 1713ea4de7
commit cc10eab7f3
  1. 19
      striker-ui/components/List.tsx

@ -14,7 +14,6 @@ import {
Theme, Theme,
} from '@mui/material'; } from '@mui/material';
import { FC, forwardRef, useCallback, useMemo } from 'react'; import { FC, forwardRef, useCallback, useMemo } from 'react';
import { v4 as uuidv4 } from 'uuid';
import { BLUE, BORDER_RADIUS, GREY, RED } from '../lib/consts/DEFAULT_THEME'; import { BLUE, BORDER_RADIUS, GREY, RED } from '../lib/consts/DEFAULT_THEME';
@ -40,7 +39,7 @@ const List = forwardRef(
insertHeader: isInsertHeader = true, insertHeader: isInsertHeader = true,
listEmpty, listEmpty,
listItemIconMinWidth = '56px', listItemIconMinWidth = '56px',
listItemKeyPrefix = uuidv4(), listItemKeyPrefix = 'list',
listItemProps: { sx: listItemSx, ...restListItemProps } = {}, listItemProps: { sx: listItemSx, ...restListItemProps } = {},
listItems, listItems,
listProps: { sx: listSx, ...restListProps } = {}, listProps: { sx: listSx, ...restListProps } = {},
@ -226,18 +225,18 @@ const List = forwardRef(
); );
}); });
}, [ }, [
loading, getListItemCheckboxProps,
listItems, isAllowItemButton,
listEmptyElement, listEmptyElement,
renderListItem, listItemCheckbox,
restListItemProps,
listItemKeyPrefix, listItemKeyPrefix,
listItemSx, listItemSx,
listItemCheckbox, listItems,
renderListItemCheckboxState, loading,
getListItemCheckboxProps,
isAllowItemButton,
onItemClick, onItemClick,
renderListItem,
renderListItemCheckboxState,
restListItemProps,
]); ]);
const listScrollSx: SxProps<Theme> | undefined = useMemo( const listScrollSx: SxProps<Theme> | undefined = useMemo(
() => (isScroll ? { maxHeight: '100%', overflowY: 'scroll' } : undefined), () => (isScroll ? { maxHeight: '100%', overflowY: 'scroll' } : undefined),

Loading…
Cancel
Save