我正在尝试将react-dnd
和react-big-calendar
一起使用,并具有拖放支持(在后台使用react-dnd
)。但是,如果我分别启动它们,则会出现错误:
Uncaught Error: Cannot have two HTML5 backends at the same time.
代码如下:
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)
...
react-big-calendar
文档mentions,withDragAndDrop()
函数可以接受后端作为第二个参数,这意味着,从理论上讲,我应该能够检索已经设置的后端实例react-dnd
并将其作为参数传递。但是,我不确定如何检索后端实例。
react-dnd
documentation for DragDropContext
提到了一个实例方法getManager()
,它可以帮助我检索后端(getManager().getBackend()
)。但是,此处的键是 instance 方法。如何从DragDropContext(HTML5Backend)(App)
文件中获取Calendar.js
的实例?