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

Sortable example doesn't work by passing ref #831

Closed
TrevorHinesley opened this issue Jul 17, 2017 · 4 comments
Closed

Sortable example doesn't work by passing ref #831

TrevorHinesley opened this issue Jul 17, 2017 · 4 comments
Labels

Comments

@TrevorHinesley
Copy link

The example is:

return connectDragSource(connectDropTarget(
      <div style={{ ...style, opacity }}>
        {text}
      </div>
    ));

But using the alternative ways to connect, such a passing ref (using innerRef because I'm using styled-components), if I do:

return (
      <MyElement 
        innerRef={instance => connectDragSource(connectDropTarget(findDOMNode(instance)))}
        style={{ ...style, opacity }}
      >
        {text}
      </MyElement>
);

Only the inner call works (in this case, connectDropTarget, but if I swap connectDropTarget and connectDragSource, then only connectDragSource will work).

This works, though:

return (
      <MyElement 
        innerRef={instance => {
          const domNode = findDOMNode(instance)
          connectDragSource(domNode)
          connectDropTarget(domNode)
        }}
        style={{ ...style, opacity }}
      >
        {text}
      </MyElement>
);

Any reason why?

@TrevorHinesley TrevorHinesley changed the title sortable example doesn't work with by passing ref Sortable example doesn't work by passing ref Jul 17, 2017
@noosxe
Copy link

noosxe commented Oct 15, 2017

Any news on this issue ?

@rholliger
Copy link

It would be great if React DnD works with Styled-Components (with innerRef) and not only native div elements.

@philraj
Copy link
Contributor

philraj commented Dec 6, 2017

I wonder how this is happening, because the connector functions are supposed to return a cloned ReactElement, and it's weird that it works fine in a rendering context. Interested to hear the explanation if any should happen to appear. :-)

@stale
Copy link

stale bot commented Jul 6, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jul 6, 2019
@stale stale bot closed this as completed Jul 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants