未在React JS中定义错误'TableData'的react / jsx-no-undef

时间:2019-04-12 05:39:21

标签: reactjs react-native

我是React JS的新手,我有2个文件,App.jsTable.js,我在App.js中包含了Table.js文件,当我使用<TableData />时,它给出了我的错误,Line 12: 'TableData' is not defined react/jsx-no-undef,在这里我已经添加了我的整个代码,有人可以帮我解释为什么给我这个错误,
App.js:

import React, { Component } from 'react';
import './App.css';
import { Button, Table } from 'react-bootstrap';
import './Table.js';

class App extends Component {
  render() {
    return (
      <div className="App">
        <p>Edit <code>src/App.js</code> and save to reload.</p>
        <Button variant="primary">Primary</Button>
        <TableData />
      </div>
    );
  }
}

export default App;

Table.js

import React, { Component } from 'react';
import { Button, Table } from 'react-bootstrap';
import './App.css';


class TableData extends Component {
  render() {
    return (
      <Table striped bordered hover>
        <thead>
          <tr>
            <th>#</th>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Username</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>1</td>
            <td>Mark</td>
            <td>Otto</td>
            <td>@mdo</td>
          </tr>
          <tr>
            <td>2</td>
            <td>Jacob</td>
            <td>Thornton</td>
            <td>@fat</td>
          </tr>
          <tr>
            <td>3</td>
            <td colSpan="2">Larry the Bird</td>
            <td>@twitter</td>
          </tr>
        </tbody>
      </Table>
    );
  }
}
export default TableData;

1 个答案:

答案 0 :(得分:3)

导入时需要定义TableData。

import TableData from './Table.js'