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

Dynamically set DropTarget type via the parent component #388

Closed
mordrax opened this issue Feb 24, 2016 · 5 comments
Closed

Dynamically set DropTarget type via the parent component #388

mordrax opened this issue Feb 24, 2016 · 5 comments

Comments

@mordrax
Copy link

mordrax commented Feb 24, 2016

In all the examples, I've seen a hardcoded DropTarget type, e.g

DropTarget(DragDropTypes.Item, target, collect)(ShopContainer);

But what I'd like to do is for the parent component to pass down a type so I can reuse the container for other DropTarget types.

<ShopContainer dropTargetType={DragDropType.AnotherType} />
//and for my drop target to dynamically set the type
DropTarget(props.dropTargetType, target, collect)(ShopContainer);

I'm currently trying to work around this by exporting multiple DropTarget containers, one for every type that I want.

@mordrax
Copy link
Author

mordrax commented Feb 24, 2016

Actually, I just figured it out. Read the doco for the 5th time and finally understood what was meant by:
A string, an ES6 symbol, an array of either, or a function that returns either of those, given component's props.
i.e

DropTarget((props) => {return props.dropTargetType;}, target, collect)(ShopContainer);

@mordrax mordrax closed this as completed Feb 24, 2016
@andrew-culver
Copy link

@mordrax I read it more than 5 times and never did get it. Now I do.

@andrew-culver
Copy link

@gaearon There should be an example like this in the docs and/or tutorial. Aside from that, I am finding them both excellent.

@nsuthar0914
Copy link

@mordrax saved my day

@mordrax
Copy link
Author

mordrax commented Dec 20, 2016

@nsuthar0914 I've moved on to Elm, give it a go, I might save you a week this time ;)

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