【问题标题】:react-grid-layout - Failed prop type: Layout property must be an object. Received: [object Array]react-grid-layout - 失败的道具类型:布局属性必须是一个对象。收到:[对象数组]
【发布时间】:2021-09-03 00:17:09
【问题描述】:

我已按照 react-grid-layout 中的指南进行操作,但仍然收到此错误消息。

这是我的布局对象:

import React from "react";
import { Responsive, WidthProvider } from "react-grid-layout";
import NewvsReturnVisitors from "./newvsreturnvisitors";
import ReactDOM from "react-dom";
import "./styles/styles.css";

const e = React.createElement;
const ResponsiveGridLayout = WidthProvider(Responsive);

function App() {

  const layout = [
    { i: "1", x: 0, y: 0, w: 2, h: 1, minW: 2, minH: 1 },
    { i: "2", x: 10, y: 0, w: 2, h: 1, minW: 2, minH: 1 }
  ];

  return (
    <ResponsiveGridLayout
      layouts={layout}
    >
      <div key="1">
        <NewvsReturnVisitors />
      </div>
    </ResponsiveGridLayout>
  );
}

ReactDOM.render(e(App), document.getElementById("root"));

我的 Codesanbox 在这里:

只需打开控制台,错误消息就在那里。将不胜感激!

【问题讨论】:

    标签: reactjs echarts apache-echarts


    【解决方案1】:

    您使用的是 react-grid-layout 版本 1.2.0,它的类型结构有一些变化

    这是新的更新类型:

    interface Layouts {
      [P: string]: Layout[];
    }
    

    要满足这一点,您需要从以下位置更改布局对象:

    const layout = [
      { i: "1", x: 0, y: 0, w: 2, h: 1, minW: 2, minH: 1 },
      { i: "2", x: 10, y: 0, w: 2, h: 1, minW: 2, minH: 1 }
    ];
    

    收件人:

    const layout = {
      xs: [{ i: "1", x: 0, y: 0, w: 2, h: 1, minW: 2, minH: 1 }],
      md: [{ i: "2", x: 10, y: 0, w: 2, h: 1, minW: 2, minH: 1 }]
    };
    

    xsmd 是断点。

    【讨论】:

      猜你喜欢
      • 2021-03-29
      • 2016-09-15
      • 2019-02-07
      • 2016-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-23
      • 1970-01-01
      相关资源
      最近更新 更多