From 30ce055986929e71f9b7b63db914cf5361caf0c8 Mon Sep 17 00:00:00 2001 From: GermanVor Date: Fri, 9 Feb 2024 13:11:07 +0100 Subject: [PATCH] chore: add useUniqId --- src/components/TreeSelect/DndTreeSelect.tsx | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/components/TreeSelect/DndTreeSelect.tsx b/src/components/TreeSelect/DndTreeSelect.tsx index 71e375b682..1c2111d193 100644 --- a/src/components/TreeSelect/DndTreeSelect.tsx +++ b/src/components/TreeSelect/DndTreeSelect.tsx @@ -4,6 +4,7 @@ import {Grip} from '@gravity-ui/icons'; import {DragDropContext, Draggable, Droppable} from 'react-beautiful-dnd'; import type {OnDragEndResponder} from 'react-beautiful-dnd'; +import {useUniqId} from '../../hooks'; import {Icon} from '../Icon'; import {ListContainerView} from '../useList'; import {reorderArray} from '../useList/__stories__/utils/reorderArray'; @@ -24,8 +25,6 @@ export type RenderDndContainer = (container: { const DEFAULT_RENDER_CONTAINER: RenderDndContainer = ({renderList}) => renderList(); -let dndTreeSelectCount = 0; - export type DndTreeSelectProps = Omit< TreeSelectProps, 'items' | 'renderContainer' | 'renderItem' @@ -43,9 +42,7 @@ export function DndTreeSelect({ renderContainer: propsRenderContainer = DEFAULT_RENDER_CONTAINER, ...treeSelectNativeProps }: DndTreeSelectProps) { - const [droppableId] = React.useState( - () => initialDroppableId || `default-droppable-id-${dndTreeSelectCount++}`, - ); + const uniqId = useUniqId(); const renderContainer = React.useCallback>( ({renderItem, visibleFlattenIds, items: _items, containerRef, id}) => { @@ -64,7 +61,7 @@ export function DndTreeSelect({ const renderList = () => ( - + {(droppableProvided) => { return (
({ return propsRenderContainer({renderList}); }, - [items, setItems, propsRenderContainer, droppableId], + [items, setItems, propsRenderContainer], ); const renderDndItem = React.useCallback>(