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
How to use a third-party component as a drag source? #347
Comments
Good question. I think you should be able to do this: import { findDOMNode } from 'react-dom';
class DraggableListGroupItem extends Component {
render() {
const { connectDragSource, ...rest } = this.props;
return (
<ListGroupItem
{...rest}
ref={instance => connectDragSource(findDOMNode(instance))}
/>
);
}
}
export default DragSource(...)(DraggableListGroupItem); This works because |
(This also gives you the freedom to use some other DOM element as the drag source—for example, you can query the node you get from |
This didn't work for me. The nesting is now correct but the element is not draggable and I get the following error in the console:
|
I believe you typed import findDOMNode from 'react-dom'; rather than import { findDOMNode } from 'react-dom'; Indeed |
I was in the middle of trying to write a reduced example but you caught the bug first! I know about the difference between default and named exports but I don't always notice which one I need and the debug tools aren't great at giving an error message that shows what's going on. I can see now how that error message points at the problem even though it's been mangled by Webpack. Thanks for the lesson! |
PS: if I were to file a pull request to add this to the docs (not sure I'll have time), where would I put it? It would help if the connectDragSource error pointed to this solution. |
Not sure, I think the current message is good enough. Now we have this issue for googling too :-) By the way I re-read your question and want to make a point that you absolutely don't have to wrap it in |
Fortunately! 😁 Just want to append a little precision, if you're used to chain the ref={instance => {
const node = findDOMNode(instance);
connectDragSource(node);
connectDropTarget(node);
}} |
Fixes some styling issues. react-dnd/react-dnd#347
2 questions on this: |
I want to use a third-party component (in this case a
<ListGroupItem>
from React Bootstrap) as a drag source. When I callconnectReactSource
on it I get an error telling meHowever, if I wrap it in a
<div>
, it will mess up my markup and styling because it is supposed to be a<li>
. The other option is to turn it into a drag source, but I don't see how to do that without editing the source of the third-party component. What is the right thing to do here?The text was updated successfully, but these errors were encountered: