Describe the bug
I upgraded dnd from 7.4.5 to 9.3.2, but the browser throw an error:
Attempted import error: 'DragDropContext' is not exported from 'react-dnd'. in 9.3.2
Reproduction
Steps to reproduce the behavior:
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
Add any other context about the problem here.
Hi, DragDropContext
was removed since version 9 https://github.com/react-dnd/react-dnd/pull/1439
Hi,
DragDropContext
was removed since version 9 #1439
oh thx
Whats the migration path now that this has been removed?
Guys, is there any migration guide for the breaking changes in the 9.x version?
Guys, is there any migration guide for the breaking changes in the 9.x version?
No, You can remind the author to update the document.
This is what I ended up doing
- import { DragDropContext } from "react-dnd";
- import HTML5Backend from "react-dnd-html5-backend";
-
- export const withDragDropContext = DragDropContext(HTML5Backend);
+ import * as React from "react";
+ import HTML5Backend from "react-dnd-html5-backend";
+ import { DndProvider } from "react-dnd";
+
+ export const withDragDropContext = <TProps extends {}>(Component: React.ComponentClass<TProps> | React.StatelessComponent<TProps>) =>
+ {
+ return (props: TProps) => (
+ <DndProvider backend={HTML5Backend}>
+ <Component {...props} />
+ </DndProvider>
+ );
+ };
For those out there googling, this might help:
THIS DOES NOT WORK
import { createDndContext, DndProvider } from "react-dnd";
import Backend from "react-dnd-html5-backend";
// ...
const DndContext = createDndContext(Backend);
// ...
const MyComponent = () => (
<DndProvider backend={Backend} context={DndContext}>
/* ... */
</DndProvider>
);
I repeat, THAT DOES NOT WORK
Instead do this:
import { createDndContext, DndProvider } from "react-dnd";
import Backend from "react-dnd-html5-backend";
// ...
const DndContext = createDndContext(Backend);
// ...
const myComponent = () => (
const managerRef = useRef(DndContext);
<DndProvider backend={Backend} manager={managerRef.current.dragDropManager}>
/* ... */
</DndProvider>
)
sources: Dnd code
how to solve
Most helpful comment
This is what I ended up doing