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

Unable to find any drag handles in the context "1"

Open Android789515 opened this issue 2 years ago • 2 comments

Screenshot 2022-05-09 100840

Screenshot 2022-05-09 100856

I have created a custom component that takes children and wraps them in the Draggable. I am cloning the children and passing the props to them from the provided object.

import React from 'react'
import { v4 as uuid } from 'uuid'
import { Draggable } from 'react-beautiful-dnd'

interface Props {
    index: number
}

const DraggableDnD: React.FC<Props> = (props) => {
    return (
        <Draggable draggableId={uuid()} index={props.index}>
            {({ innerRef, draggableProps, dragHandleProps }) => {
                if (React.isValidElement(props.children)) {
                    const propsToPass = {
                        innerRef: innerRef,
                        ...props.children.props,
                        ...draggableProps,
                        ...dragHandleProps
                    }

                    return React.cloneElement(props.children, propsToPass)
                }

                return <></>
            }}
        </Draggable>
    )
}

export default DraggableDnD

Android789515 avatar May 09 '22 15:05 Android789515

Simplified my code a lot and no longer needed to clone anything, fixed my issue. I would still like to know why I was encountering the error though.

Android789515 avatar May 11 '22 00:05 Android789515

hey what did you do im getting the same error

zakim2307 avatar May 11 '22 14:05 zakim2307