Import Issue for React-Table

2020-04-19 23:19发布

问题:

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?

回答1:

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).



回答2:

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.



回答3:

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



回答4:

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