简体   繁体   English

提供给“DataProvider”的类型为“number”的无效道具“data”,应为“array”。 React-bootstrap-table2, Firebase 实时数据库

[英]Invalid prop `data` of type `number` supplied to `DataProvider`, expected `array`. React-bootstrap-table2, Firebase Realtime Database

I've been trying to retrieve data from Firebase Realtime Database and display it in react-bootstrap-table2, but I've run into some issues when it comes to actually displaying the data.我一直在尝试从 Firebase 实时数据库中检索数据并将其显示在 react-bootstrap-table2 中,但是在实际显示数据时遇到了一些问题。 When I run the code I get an error: Failed prop type: Invalid prop data of type number supplied to DataProvider , expected array .当我运行代码时,我收到一个错误: Failed prop type: Invalid prop data of type number provided to DataProvider , expected array

Here is my code:这是我的代码:

const App = () => {
  const [timestamp, setTimestamp] = useState([]);
  const [loading, setLoading] = useState(false);
  const getTimestamp = () => {
    const database = db.ref("timestamped_measures");
    database.on("value", (ts_measures) => {
      ts_measures.forEach((ts_measure) => {
        setTimestamp(ts_measure.val().timestamp);
      });
    });
  };

  const columns = [{ dataField: "timestamp", text: "Timestamp" }];
  useEffect(() => {
    getTimestamp();
  }, []);
  return (
    <div className="App">
      <BootstrapTable
        keyField="timestamp"
        data={timestamp}
        columns={columns}
        pagination={paginationFactory()}
      />
    </div>
  );
};

export default App;

This is what my Firebase database looks like这就是我的 Firebase 数据库的样子

Any help would be appreciated!任何帮助,将不胜感激!

Edit: console.log(timestamp) console.log(typeof timestamp)编辑: console.log(timestamp) console.log(typeof timestamp)

You need to map your timestamp results from ts_measures into an array, and store it in state.您需要将 ts_measures 中的时间戳结果 map 放入一个数组中,并将其存储在 state 中。 I assume, since your columns contain a datafield "timestamp", each of your data rows would require this key which would hold the data for the TimeStamp column.我假设,由于您的列包含一个数据字段“时间戳”,因此您的每个数据行都需要这个键来保存时间戳列的数据。

{timestamp: ts_measure.val().timestamp} 

Give this a shot试一试

const getTimestamp = () => {
  const database = db.ref("timestamped_measures");
  database.on("value", (ts_measures) => {
   setTimestamp(ts_measures.map((ts_measure) => {
      return {timestamp: ts_measure.val().timestamp}
    }));
  });
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 react-big-calendar ERROR:提供给`Popup`的&#39;date`类型的prop`plotStart`无效,期望的`number` - react-big-calendar ERROR: Invalid prop `slotStart` of type `date` supplied to `Popup`, expected `number` 提供给 textinput 预期字符串的类型编号的无效道具值反应本机 - invalid prop value of type number supplied to textinput expected string react native 提供给叠加层的“数组”类型的道具“子项”无效。 期望单个反应元素 - Invalid prop 'children' of type 'array' supplied to overlay. Expected a single react element React Native SearchBar错误:道具类型失败:提供给`ForwardRef(TextInput)`的`array`类型的无效道具`value`,预期`string` - React Native SearchBar Error: Failed prop type: Invalid prop `value` of type `array` supplied to `ForwardRef(TextInput)`, expected `string` %s 类型失败:%s%s,道具,提供给“图像”的无效道具“来源”,应为 [数字] 类型之一 - Failed %s type: %s%s, prop, Invalid prop `source` supplied to `Image`, expected one of type [number] 道具类型失败:提供给“ForwardRef(TablePagination)”的“string”类型的道具“count”无效,应为“number” - Failed prop type: Invalid prop `count` of type `string` supplied to `ForwardRef(TablePagination)`, expected `number` 道具类型失败:提供给Styled(Container)的类型为number的道具类型无效,预期对象 - Failed prop type: Invalid prop `style` of type `number` supplied to `Styled(Container)`, expected `object` 失败的道具类型:向“表”提供了“功能”类型的道具“ rowSelection”无效,预期是“对象” - Failed prop type: Invalid prop `rowSelection` of type `function` supplied to `Table`, expected `object` 开玩笑:道具类型失败:提供给“图像”的道具“来源”无效,应为 [数字] 类型之一 - Jest: Failed prop type: Invalid prop `source` supplied to `Image`, expected one of type [number] 道具类型失败:提供给“ForwardRef(DataGrid)”的“object”类型的无效道具“rows”,预期为“array” - Failed prop type: Invalid prop `rows` of type `object` supplied to `ForwardRef(DataGrid)`, expected `array`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM