Uncaught TypeError: (0 , _reactTable.useTable) is not a function

Uncaught TypeError: (0 , _reactTable.useTable) is not a function

尝试遵循以 editable 方式使用 react-table 的工作示例: https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/editable-data

我完全复制并粘贴了代码,但无法使其正常工作。

在网上搜索,我知道错误的一个常见原因是没有使用花括号导入非默认导出(这是)。

我对 javascript/react 等(通常在 .net 中工作)非常陌生,所以我假设这是非常基础的东西。

作为故障排除步骤,我已将两个导入分成不同的行,但输出没有变化:

import { useTable } from 'react-table'
import { usePagination } from 'react-table'

这是我的 package.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "ci": "npm run lint -- ./src && npm run jest",
    "start": "npm run webpack-dev-server",
    "build": "set NODE_ENV=dev&& npm run webpack",
    "test": "node --inspect=0.0.0.0:9229 ./node_modules/jest/bin/jest --watchAll",
    "jest": "./node_modules/.bin/jest",
    "lint": "./node_modules/.bin/eslint",
    "webpack": "./node_modules/.bin/webpack",
    "webpack-dev-server": "./node_modules/.bin/webpack-dev-server"
  },
  "author": "",
  "license": "UNLICENSED",
  "dependencies": {
    "babel-plugin-syntax-dynamic-import": "^6.18.0",
    "carbon-react": "^4.0.0",
    "create-carbon-app": "^1.0.3",
    "namor": "^1.1.2",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-router": "^5.0.1",
    "react-router-dom": "^5.0.1",
    "react-table": "^6.10.0",
    "styled-components": "^4.3.2"
  },
  "devDependencies": {
    "carbon-factory": "^5.0.0",
    "enzyme": "^3.0.0",
    "enzyme-adapter-react-16": "^1.0.0",
    "webpack-cli": "^3.3.6",
    "webpack-dev-server": "^3.7.1"
  }
}

如果我一起删除该行,那么我会得到 "useTable is not defined" 希望有人能给我指出 check/investigate 的方向,而不仅仅是用花括号导入。

您正在使用 react-table 版本 6.10.0useTable 是在目前处于 alpha 的版本 7 中引入的,如果你想使用它,你需要安装 v7.0.0-alpha.2

所以在你的 package.json

"react-table": "^6.10.0",

需要

"react-table": "v7.0.0-alpha.2",

然后 运行 npm install 重新安装正确的版本