react-drag-drop-container icon indicating copy to clipboard operation
react-drag-drop-container copied to clipboard

When switching to Preact, this.containerElem is undefined

Open anshulm-soc opened this issue 3 years ago • 0 comments

this.containerElem is undefined after switching to preact

it gives following error:

debug.module.js:5 Uncaught TypeError: Cannot read properties of undefined (reading 'getElementsByTagName')

In the following code, t is undefined:

return h.default.createElement("div", {
                        className: "ddcontainer",
                        style: a,
                        ref: function(t) {
                            e.containerElem = t. //this is undefined
                        }
                    }, h.default.createElement("span", {
                        className: "ddcontainersource",
                        style: u,
                        ref: function(t) {
                            e.sourceElem = t
                        }
                    }, t), i)

My Code:

                           <DragDropContainer
                                    dragData={{
                                        id: `drag_${op.index}_${props.quesIndex}`,
                                        chosenIndex: op.index,
                                        text: op.choice,
                                    }}
                                    targetKey={`socDropClozeZone${props.quesIndex}`}
                                    onDrop={props.onDrop}
                                    onDragEnd={props.onDragEnd}
                                >
                                    <div
                                        key={`${op.index}`}
                                        className="stw-text-white stw-bg-purple-400 stw-text-base stw-rounded stw-px-4 stw-py-1 md:stw-py-2 md:stw-px-5 stw-mr-5 stw-my-2"
                                    >
                                        <SetPureHTML html={op.choice} latex={props?.latex} />
                                    </div>
                                </DragDropContainer>

if I switch back to React then it works fine.

Please let me know what I am doing wrong here. Thanks in advance!!

anshulm-soc avatar Mar 03 '22 05:03 anshulm-soc