react-beautiful-dnd icon indicating copy to clipboard operation
react-beautiful-dnd copied to clipboard

Is it a good idea to mix dnd related code inside of components?

Open gitleet opened this issue 8 years ago • 1 comments

If I am creating components in my react app, say like a Board, List and Card controls. Is it a good idea to mix dnd code inside of my components?

Will this limit how I can use dnd? Say sometimes a component is in a vertical list, and other times it is in a horizontal list etc. Will I am locking myself into a certain use of my component?

Just looking for some wisdom in this regards as I am just starting out using dnd.

Thanks!

gitleet avatar Oct 18 '18 01:10 gitleet

Hi @gitleet,

It is hard to give you direction without a specific use case.

It is a common pattern to have a component (eg <Item />) that is wrapped by a Draggable that you pass in the information you care about from the Draggable. However, Item would still need to accept things like DraggableProps and DragHandleProps so it is not a strong seperation.

Thankfully the API for react-beautiful-dnd is super light so changing between your own internal abstractions should be relatively painless.

I would recommend choosing an approach that feels simple and straightforward, and then move to something more complicated if the need arrises

👍

alexreardon avatar Oct 21 '18 22:10 alexreardon