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

DragDropContextProvider creates new backend on each update #858

Closed
WearyMonkey opened this issue Aug 23, 2017 · 0 comments
Closed

DragDropContextProvider creates new backend on each update #858

WearyMonkey opened this issue Aug 23, 2017 · 0 comments

Comments

@WearyMonkey
Copy link
Contributor

DragDropContextProvider creates a new backend on each call to getChildContext. getChildContext is called on each update. This results in Cannot have two HTML5 backends at the same time error if a draggable child is added.

Example to reproduce:

import * as React from 'React';
import * as ReactDOM from 'react-dom';
import { DragDropContextProvider, DropTarget } from 'react-dnd';
import ReactDnDHTML5Backend from 'react-dnd-html5-backend';

class Parent extends React.Component<{}, { count: number }> {

  constructor() {
    super();
    this.state = { count: 1 };
  }

  render() {
    return (
        <div>
          <button onClick={() => this.setState({ count: this.state.count + 1 })}>Add</button>
          <DragDropContextProvider backend={ReactDnDHTML5Backend}>
            <div>
              {Array(this.state.count).fill(null).map((_, i) => (
                  <Target key={i} />
              ))}
            </div>
          </DragDropContextProvider>
        </div>
    );
  }
}

@DropTarget('foo', { }, (connect, monitor) => ({ }))
class Target extends React.Component {
  render() {
    return <div>Hello</div>;
  }
}

ReactDOM.render(<Parent />, document.getElementById('root'));

No error if @DragDropContent decorator is used directly as it creates the context once on initialisation.

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

2 participants