Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not import DragDropContext in v9.3.2 #1489

Closed
shenghou opened this issue Jul 24, 2019 · 9 comments
Closed

Can not import DragDropContext in v9.3.2 #1489

shenghou opened this issue Jul 24, 2019 · 9 comments

Comments

@shenghou
Copy link

shenghou commented Jul 24, 2019

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

DEMON

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.
image

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [ chrome last version]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

@adiosneo
Copy link

Hi, DragDropContext was removed since version 9 #1439

@shenghou
Copy link
Author

Hi, DragDropContext was removed since version 9 #1439

oh thx

@hisuwh
Copy link

hisuwh commented Aug 5, 2019

Whats the migration path now that this has been removed?

@alencarlucas
Copy link

Guys, is there any migration guide for the breaking changes in the 9.x version?

@shenghou
Copy link
Author

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.

@hisuwh
Copy link

hisuwh commented Aug 12, 2019

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>
+     );
+ };

@ldd
Copy link

ldd commented Apr 24, 2020

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

@Liruimin2
Copy link

how to solve

@1Jesper1
Copy link

1Jesper1 commented Jan 4, 2022

As decorator component:

import * as React from 'react';
import { HTML5Backend } from 'react-dnd-html5-backend';
import { DndProvider } from 'react-dnd';

const DragDropContext = (WrappedComponent) => (props) => {
	return  (<DndProvider backend={HTML5Backend}>
		<WrappedComponent {...props} />
	</DndProvider>);
};

export default DragDropContext;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants