【问题标题】:Why the react table is not rendering my data?为什么反应表没有呈现我的数据?
【发布时间】:2020-04-14 12:55:39
【问题描述】:

我想展示在 react js 上使用 React Table 的数据,我按照网站上的说明进行操作。这是我的代码:

import React, { Component } from 'react';  
import './App.css';
import ReactTable from "react-table";  


class App extends Component {  
  render() {  
     const data = [{  
        name: 'Ayaan',  
        age: 26  
        },{  
         name: 'Ahana',  
         age: 22  
         },{  
         name: 'Peter',  
         age: 40      
         },{  
         name: 'Virat',  
         age: 30  
         },{  
         name: 'Rohit',  
         age: 32  
         },{  
         name: 'Dhoni',  
         age: 37  
         }]  
     const columns = [{  
       Header: 'Name',  
       accessor: 'name'  
       },{  
       Header: 'Age',  
       accessor: 'age'  
       }]  
    return (  
      <ReactTable  
      data={data}  
      columns={columns}  
      defaultPageSize = {2}  
      pageSizeOptions = {[2,4, 6]}  
      >  
      </ReactTable>      
    )  
  }  
}  
export default App;  

但是我遇到了一些错误,例如: enter image description here

这是我的依赖项:

"dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "axios": "^0.19.2",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-scripts": "3.4.1",
    "react-table": "^7.0.4"
  }

我知道这个版本会给我带来什么麻烦。

【问题讨论】:

  • 这是来自图像的错误:错误:元素类型无效:期望字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。您可能忘记从定义组件的文件中导出组件,或者您可能混淆了默认导入和命名导入。
  • 检查所有导入。您可能在某处添加了一些额外的花括号

标签: reactjs react-table


【解决方案1】:

您可能正在使用一个旧示例。请关注:How to create a Simple react-table

【讨论】:

    猜你喜欢
    • 2019-08-09
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 2020-12-27
    • 1970-01-01
    相关资源
    最近更新 更多