fix(explore): fix undefined error when using dnd (#16020)

This commit is contained in:
Kamil Gabryjelski
2021-08-02 15:22:32 +02:00
committed by GitHub
parent c77bf264d1
commit 3061b6ad09
9 changed files with 395 additions and 277 deletions

View File

@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import React, { useRef } from 'react';
import React, { useMemo, useRef } from 'react';
import {
useDrag,
useDrop,
@@ -24,7 +24,6 @@ import {
DragSourceMonitor,
} from 'react-dnd';
import { DragContainer } from 'src/explore/components/controls/OptionControls';
import { DndItemType } from 'src/explore/components/DndItemType';
import {
OptionProps,
OptionItemInterface,
@@ -33,7 +32,7 @@ import Option from './Option';
export default function OptionWrapper(
props: OptionProps & {
type: DndItemType;
type: string;
onShiftOptions: (dragIndex: number, hoverIndex: number) => void;
},
) {
@@ -50,10 +49,13 @@ export default function OptionWrapper(
} = props;
const ref = useRef<HTMLDivElement>(null);
const item: OptionItemInterface = {
dragIndex: index,
type,
};
const item: OptionItemInterface = useMemo(
() => ({
dragIndex: index,
type,
}),
[index, type],
);
const [, drag] = useDrag({
item,
collect: (monitor: DragSourceMonitor) => ({