I'm trying to implement DnD functionality in react-data-grid
, but I'm getting "TypeError: Object(...) is not a function" Error
.
There is a same file in TypeSript that I provided in the sandbox(it is only for reference). I'm trying to implement the functionality in React and something is wrong when converting TS code to React code.
I'm using react-data-grid
^7.0.0-canary.33.
<DndProvider backend={HTML5Backend}>
<DataGrid
rowRenderer={p => <DraggableRowRenderer {...p} onRowReorder={onRowReorder} />}
/>
</DndProvider>
// this is the component where the error is. I think I'm doing something wrong when typing react code(the orignal implementation is in TS)
import { useDrag, useDrop } from 'react-dnd';
import { Row } from 'react-data-grid';
import useCombinedRefs from 'react-data-grid';
// import { row } from 'react-dnd'
import clsx from 'clsx';
import './DraggableRowRenderer.less';
export default function DraggableRowRenderer({
rowIdx,
isRowSelected,
className,
onRowReorder,
...props}) {
const [{ isDragging }, drag] = useDrag({
item: { index: rowIdx, type: 'ROW_DRAG' },
collect: monitor => ({
isDragging: monitor.isDragging()
})
});
const [{ isOver }, drop] = useDrop({
accept: 'ROW_DRAG',
drop({ index, type }) {
if (type === 'ROW_DRAG') {
onRowReorder(index, rowIdx);
}
},
collect: monitor => ({
isOver: monitor.isOver(),
canDrop: monitor.canDrop()
})
});
className = clsx(
className,
{
'rdg-row-dragging': isDragging,
'rdg-row-over': isOver
}
);
return (
<Row
ref={useCombinedRefs(drag, drop)}
rowIdx={rowIdx}
isRowSelected={isRowSelected}
className={className}
{...props}
/>
);
}