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

HOOKS! #7

Closed
waynevanson opened this issue Jul 20, 2019 · 7 comments
Closed

HOOKS! #7

waynevanson opened this issue Jul 20, 2019 · 7 comments

Comments

@waynevanson
Copy link

Thanks for creating this example.

Is it possible to do nested with hooks?

I've been trying but to no avail.

@waynevanson
Copy link
Author

From actually starting to understand how this thing works, it looks like you're referencing instances (this) which are only available on classes. I can't see any other way to make this work without using classes.

Thanks for the example!

@waynevanson
Copy link
Author

On closer inspection, it looks like this could be done with the new hooks in a functional component. I will post an example when I figure it out. I noticed that this was only used because app/containers/index.js is a class and the functions needed to be bound. Using a store, this isn't necessary.

I do have a question, however. Where does props.id come from in this file? id is not passed as a prop to components/tree

hover(props, monitor) {
const {id: draggedId, parent, items} = monitor.getItem()
if (!monitor.isOver({shallow: true})) return
const descendantNode = props.find(props.parent, items)
if (descendantNode) return
if (parent == props.parent || draggedId == props.parent) return
props.move(draggedId, props.id, props.parent)

@waynevanson waynevanson reopened this Jul 20, 2019
@max-sym
Copy link

max-sym commented May 6, 2020

@waynevanson Hi! Were you able to solve it?

@tamagokun
Copy link
Owner

🤦 my notifications must be messed up, because this is the first i'm seeing this issue, so sorry about that!

props comes from the DropTarget hoc, though here it's being as a decorator, which should probably be undone, but oh well. If you look at DropTarget, that function is the "drop target specification" which is detailed here: https://react-dnd.github.io/react-dnd/docs/api/drop-target#drop-target-specification It will pass in the props of the component so you can control what gets dropped

@tamagokun
Copy link
Owner

Sorry, to answer your original question, props refers to the props of the particular component being dropped, not the tree itself.

@max-sym
Copy link

max-sym commented May 7, 2020

Thanks for your reply!

I've noticed that props.id is always undefined in line where
props.move(draggedId, props.id, props.parent) is called.

Trying to convert it to hooks now.

UPDATE: Oh ok, it's undefined only in the <Tree /> component's hover, not in the <Item />'s hover. Sorry :)

@max-sym
Copy link

max-sym commented May 7, 2020

Pull request!
Maybe a bit messy, but here it is: #8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants