Skip to content

Commit

Permalink
chore: add useUniqId
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanVor committed Feb 9, 2024
1 parent a70ee5e commit 30ce055
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/components/TreeSelect/DndTreeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -24,8 +25,6 @@ export type RenderDndContainer = (container: {

const DEFAULT_RENDER_CONTAINER: RenderDndContainer = ({renderList}) => renderList();

let dndTreeSelectCount = 0;

export type DndTreeSelectProps<T extends DndTreeSelectItem> = Omit<
TreeSelectProps<T>,
'items' | 'renderContainer' | 'renderItem'
Expand All @@ -43,9 +42,7 @@ export function DndTreeSelect<T extends DndTreeSelectItem>({
renderContainer: propsRenderContainer = DEFAULT_RENDER_CONTAINER,
...treeSelectNativeProps
}: DndTreeSelectProps<T>) {
const [droppableId] = React.useState(
() => initialDroppableId || `default-droppable-id-${dndTreeSelectCount++}`,
);
const uniqId = useUniqId();

const renderContainer = React.useCallback<RenderContainerType<DndTreeSelectItem>>(
({renderItem, visibleFlattenIds, items: _items, containerRef, id}) => {
Expand All @@ -64,7 +61,7 @@ export function DndTreeSelect<T extends DndTreeSelectItem>({
const renderList = () => (
<ListContainerView ref={containerRef} id={id}>
<DragDropContext onDragEnd={handleDrugEnd}>
<Droppable droppableId={droppableId}>
<Droppable droppableId={initialDroppableId ?? uniqId}>
{(droppableProvided) => {
return (
<div
Expand All @@ -83,7 +80,7 @@ export function DndTreeSelect<T extends DndTreeSelectItem>({

return propsRenderContainer({renderList});
},
[items, setItems, propsRenderContainer, droppableId],
[items, setItems, propsRenderContainer],
);

const renderDndItem = React.useCallback<RenderItem<DndTreeSelectItem>>(
Expand Down

0 comments on commit 30ce055

Please sign in to comment.