Import Issue for React-Table

2020-04-19 23:20发布

I am creating a table in react using react-table library. Few days back, I had created a table using the same library and faced no issues. But today I am getting the following error.

Attempted import error: 'react-table' does not contain a default export (imported as 'ReactTable').

Import Statement: import ReactTable from 'react-table';

I created multiple new projects from scratch and installed the node modules.

Is there any way to resolve this issue?

4条回答
贼婆χ
2楼-- · 2020-04-20 00:07

You're doing it in the version 6 way, and installing a later version of react-table. Based on comment found here: React table does not contain a default export, you need to install react-table-6 instead of react-table and replace it as well on your imports.

查看更多
小情绪 Triste *
3楼-- · 2020-04-20 00:13

You need to use the react-table-6

Use this command using Terminal or Command Prompt

> npm i react-table-6 --save

import ReactTable from 'react-table-6';

import 'react-table-6/react-table.css';

Now it will work

查看更多
Deceive 欺骗
4楼-- · 2020-04-20 00:14

I don't know which version of React Table you're using, but looking at the code of the latest version (here), there is no default export, neither a ReactTable export.

It seems that it is now using hooks, so you should use the useTable hook to create a table with the latest version (doc here).

查看更多
够拽才男人
5楼-- · 2020-04-20 00:15

Solved the problem!!!

You have to install

npm install react-table-6

and then import

import React, {Component} from 'react';

import ReactTable from 'react-table-6';

import 'react-table-6/react-table.css';

its solved:) Reference https://www.npmjs.com/package/react-table-6

查看更多
登录 后发表回答