reactjs - react-grid-layout - 失败的 Prop 类型 : Layout property must be an object. 已收到:[对象数组]

标签 reactjs echarts apache-echarts

我已按照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 在这里:

Edit React Grid Layout with Resizable (forked)

只要打开控制台,就会出现错误消息。将不胜感激任何帮助!

最佳答案

您正在使用 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是断点。

关于reactjs - react-grid-layout - 失败的 Prop 类型 : Layout property must be an object. 已收到:[对象数组],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69038253/

相关文章:

javascript - Apache ECharts - 带折线图范围选择的画笔

reactjs - 如何使用 webpack 内联样式?

python - 将 React 应用程序的构建包含到 Flask 中的正确方法

javascript - "echarts"' has no exported member named ' EChartOption '. Did you mean ' EChartsOption' 代替?

javascript - 如何使用 eCharts 显示每日股票图表和季度收入数据图表

javascript - ECharts LinearGradient 的 API 是如何工作的?

javascript - 更改 google-maps-react 上选定多边形的颜色

javascript - 使用包含凭据的 URL 进行请求

javascript - 百度Echarts添加拖拽选项Polar