question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pass an existing backend to withDragAndDrop - a practical example

See original GitHub issue

I’m attempting to use react-dnd and react-big-calendar withDragAndDrop in an app together. However, if I initiate them separately, I get an error:

Uncaught Error: Cannot have two HTML5 backends at the same time.

I know this error has already been discussed in a few tickets, like this one. However, looking at the current documentation of withDragAndDrop it appears that the solution in the PR linked from above-mentioned ticket has been replaced with an optional backend that can be passed.

The big question for me is - how do I get the same backend instance so I can use it in two places?

Here’s my code:

App.js

import React from 'react'
import {DragDropContext} from 'react-dnd'
import HTML5Backend from 'react-dnd-html5-backend'
import Calendar from './Calendar'

class App extends React.Component {
  render() {
    return {
      <div>
        ...
        <Calendar />
      </div>
    }
  }
}

export default DragDropContext(HTML5Backend)(App)

Calendar.js

import React from 'react'
import BigCalendar from 'react-big-calendar'
import withDragAndDrop from 'react-big-calendar/lib/addons/dragAndDrop'

const Calendar = withDragAndDrop(BigCalendar)
...

As you can see, my Calendar component is a child of my App component where I set the react-dnd DragDropContext. So, how do I pass the same backend instance down to the Calendar component?

react-dnd documentation for DragDropContext mentions an instance method getManager() which should help me retrieve the backend (getManager().getBackend()). However, the key here is instance method. How do I get the instance of DragDropContext(HTML5Backend)(App) from my Calendar.js file?

I’m quite new to React, and I have a feeling the answer is quite trivial, I just can’t figure it out. I will appreciate any help!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
artoorascommented, Jul 30, 2018

We have. Just for those running into the same issue and looking for an answer, the secret is to explicitly omit a backend from withDragAndDrop, like so:

const DragAndDropCalendar = withDragAndDrop(BigCalendar, { backend: false })

0reactions
AbeColecommented, Nov 30, 2018

+1 @artooras Thank for you this, have just spent many hours trying to find/understand what to do here with a lot of different threads giving help but no real answer. If you hadn’t added this comment I would still be wondering what you managed to resolve on Discord.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pass an existing backend to withDragAndDrop - a practical ...
I'm attempting to use react-dnd and react-big-calendar withDragAndDrop in an app together. However, if I initiate them separately, ...
Read more >
Your First React and TypeScript Application: Building Trello ...
Our application will also store the state on the backend. So we will discuss how to use fetch with TypeScript. So in this...
Read more >
Building a Trello Clone with React DnD - LogRocket Blog
React DnD uses HTML5 drag and drop by default, but alternately, you can use the backend of your choice, creating your own custom...
Read more >
Get backend instance from react-dnd - Stack Overflow
I'm attempting to use react-dnd and react-big-calendar with drag-n-drop support (using react-dnd under the hood as well) in an app together.
Read more >
imgui_demo.cpp - Google Git
Have the ImGui::ShowDemoWindow() function wired in an always-available ... If you use one of the default imgui_impl_XXXX.cpp rendering back-end, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found