gpt4 book ai didi

reactjs - react 网格布局错误 : not mounted on DragStart

转载 作者:行者123 更新时间:2023-12-04 07:49:25 25 4
gpt4 key购买 nike

当尝试在我的 ResponsiveGridLayout 中拖动或调整任何面板的大小时,我收到以下错误:<DraggableCore> not mounted on DragStart!这是我的 GridLayout:

<ResponsiveGridLayout
className="layout"
cols={{ lg: 12, md: 10, sm: 6, xs: 4, xxs: 2 }}
onLayoutChange={(layout, allLayouts) => handleLayoutChange(allLayouts)}
rowHeight={30}
layouts={layouts}
measureBeforeMount={false}
compactionType="vertical"
useCSSTransforms={true}
>
<Panel key="a" title="Interactions per country">
<PieGraph />
</Panel>
</ResponsiveGridLayout>
这是每个单独的面板:
export const Panel: React.FC<IPanelProps> = (props) => {
const {className, children, title, shouldScroll, ...defaultPanelProps} = props;
let scrollClass = shouldScroll ? " scroll-y" : "";

return (
<div {...defaultPanelProps} className={`custom-panel wrapper ${className}`} >
{title && <div className="custom-panel-title text-medium">{title}</div>}

<div className={`custom-panel-content ${scrollClass}`} onMouseDown={ e => e.stopPropagation() }>
{children}
</div>
</div>
);
};

最佳答案

我通过在自定义 <Panel/> 中添加“ref”来解决此问题成分。只有当您的 react-grid-layout 中有自己的组件(而不是带键的 div)时,才会出现此错误。
要创建 ref 只需执行 const ref = React.createRef()并将其传递给您的自定义面板组件,如下所示:

<ResponsiveGridLayout
className="layout"
cols={{ lg: 12, md: 10, sm: 6, xs: 4, xxs: 2 }}
onLayoutChange={(layout, allLayouts) => handleLayoutChange(allLayouts)}
rowHeight={30}
layouts={layouts}
measureBeforeMount={false}
compactionType="vertical"
useCSSTransforms={true}
>
<Panel ref={ref} key="a" title="Liters per active country">
<PieGraph />
</Panel>
</ResponsiveGridLayout>
您的自定义面板变为:
export const Panel = React.forwardRef((props: IPanelProps, ref) => {
const { className, children, title, shouldScroll, ...defaultPanelProps } = props as any;
let scrollClass = shouldScroll ? " scroll-y" : "";

return (
<div ref={ref} {...defaultPanelProps} className={`custom-panel wrapper ${className}`} >

{title && <div className="custom-panel-title text-medium">{title}</div>}

<div className={`custom-panel-content ${scrollClass}`} onMouseDown={e => e.stopPropagation()}>
{children}
</div>
</div>
);
});
请注意 React.forwardRef((props: IPanelProps, ref)ref={ref} 的 Prop .

关于reactjs - react 网格布局错误 : <DraggableCore> not mounted on DragStart,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67053157/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com