I have a list of items realized as a React compontent. This list is a "Toolbox". If I start dragging an item from this list I want it to be represented as an instance of a React compontent.
My first approach was to just return a React.render(<MyReactDiv>, document.body)
in my customized jQuery helper-function but I can't get it running.
Any suggestions?
So far my code is (ES6)
ListPage.js
import React from 'react'
import MyReactDiv from './myReactDiv'
import $ from 'jquery'
import draggable from 'jquery-ui/draggable'
export default React.createClass({
render () {
return (
<div>
<ul>
<li className='draggableLI'>one</li>
<li className='draggableLI'>two</li>
<li className='draggableLI'>three</li>
</ul>
</div>)
},
componentDidMount () {
$('.draggableLI').draggable({
// helper: 'clone', // <-- I dont want to clone the li
helper: () => { // ... but want to return an instance of MyReactDiv during dragging
// not working:
// let content = React.render(<MyReactDiv>, document.body)
// return content
// working but duplicated code:
return $('<div>A Div</div>')
}
})
}
}
MyReactDiv.js
import React from 'react'
export default React.createClass({
render () {
return (<div>A Div</div>)
}
}