例子是:
return connectDragSource(connectDropTarget(
<div style={{ ...style, opacity }}>
{text}
</div>
));
但是使用其他连接方式,例如传递 ref (使用 innerRef 因为我使用的是styled-components
),如果我这样做:
return (
<MyElement
innerRef={instance => connectDragSource(connectDropTarget(findDOMNode(instance)))}
style={{ ...style, opacity }}
>
{text}
</MyElement>
);
只有内部调用有效(在这种情况下, connectDropTarget
,但如果我交换connectDropTarget
和connectDragSource
,则只有connectDragSource
有效)。
不过,这有效:
return (
<MyElement
innerRef={instance => {
const domNode = findDOMNode(instance)
connectDragSource(domNode)
connectDropTarget(domNode)
}}
style={{ ...style, opacity }}
>
{text}
</MyElement>
);
有什么理由吗?
关于这个问题的任何消息?
如果 React DnD 与 Styled-Components(使用 innerRef)一起工作而不仅仅是原生 div 元素,那就太好了。
我想知道这是怎么发生的,因为连接器函数应该返回一个克隆的 ReactElement,奇怪的是它在渲染上下文中工作正常。 有兴趣听听解释,如果有的话应该碰巧出现。 :-)
此问题已自动标记为过时,因为它最近没有活动。 如果没有进一步的活动发生,它将被关闭。 感谢你的贡献。
最有用的评论
关于这个问题的任何消息?