【问题标题】:How to solve react-table error:- TypeError: plugin is not a function如何解决 react-table 错误:- TypeError: plugin is not a function
【发布时间】:2021-09-10 07:50:00
【问题描述】:

我使用 react-table 和 useTable 钩子创建了一个基本的反应表。我收到此错误:

TypeError: plugin is not a function.

我该如何解决这个错误?

这是我的代码:

import Reactt,{ useMemo } from 'react'
import { useTable } from "react-table";
import COLUMNS from "./columns";
import MOCK_DATA from '../MOCK_DATA.json'
import '../table.css'
const BasicTable = () => {
const columns = useMemo(() => COLUMNS, []);
const data = useMemo(() => MOCK_DATA, []);   
const tableInstance = useTable(
 columns,
 data,
 )
 const {getTableProps,getTableBodyProps,headerGroups,rows,prepareRow}= tableInstance
  return (
        <table {...getTableProps()}>
         <thead>
            {
              headerGroups.map((headerGroup)=>(
               <tr{...headerGroup.getHeaderGroupProps()}>
                 {headerGroup.headers.map((column)=>(
                    <th{...column.getHeaderGroups()}>{column.render('Header')}</th>
               ))} </tr>
                        ))
                    }
                </thead>
                <tbody {...getTableBodyProps()}>
                    {
                        rows.map((row)=>{
                            prepareRow(row)
                            return(
                                <tr{...row.getRowProps()}>
                                {row.cells.map((cell)=>{
                                return <td{...cell.getCellProps()}>{cell.render('cell')}</td>
                                })}
                                </tr>
                            )
                        })
                    }
                </tbody>
            </table>
        )
    }  
export default BasicTable

【问题讨论】:

    标签: reactjs react-table


    【解决方案1】:

    您应该将columnsdata 作为选项对象传递。改为这样做

    useTable({columns,data})
    

    https://react-table.tanstack.com/docs/api/useTable#usetable

    【讨论】:

      【解决方案2】:

      也不确定它是否会弄乱你的代码,但你写的是“import Reactt”而不是“import React

      【讨论】:

      • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-22
      • 2018-09-01
      • 2018-11-14
      • 2021-07-02
      • 2021-08-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多