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

component is null in beginDrag? #530

Closed
willdady opened this issue Sep 9, 2016 · 5 comments
Closed

component is null in beginDrag? #530

willdady opened this issue Sep 9, 2016 · 5 comments
Labels

Comments

@willdady
Copy link

willdady commented Sep 9, 2016

The documentation says component is passed to beginDrag (3rd parameter) however it seems to be null when called? Not sure if it's something I'm doing wrong. If it helps my component is both a drag source and drag target.

What I am wanting to do is get the height of my component inside beginDrag, this is not something I can derive from the props passed so I need access to the component.

@willdady
Copy link
Author

Turns out the issue is DnD doesn't like stateless components :(

I changed

const SortableListItem = (props) => {

to

class SortableListItem extends Component {

and component is now correctly passed to beginDrag. It's worth mentioning the stateless component otherwise worked as expected so was quite confused why component is null in beginDrag.

It might be worth updating the beginDrag documentation to state DnD doesn't work with stateless components (assuming this can't be fixed).

@jmar777
Copy link

jmar777 commented Dec 20, 2016

Oof, just waisted a few cycles on this too (except with the hover() callback instead). Thanks so much for posting this... I had no clue where to look next.

@alextreppass
Copy link

alextreppass commented Nov 14, 2017

Ran into this just now also -- suspect the issue is stateless components have no public instance. React-dnd may need to tweak how they use refs, as receiveComponent is called with null

@Kadrian
Copy link

Kadrian commented May 20, 2019

This just happened to me when upgrading react-redux, and DragSource wrapping a connected component directly.

Workaround: switched the order of DragSoruce and connect. :-/

@stale
Copy link

stale bot commented Jul 19, 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 19, 2019
@stale stale bot closed this as completed Jul 26, 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