简体   繁体   English

reactjs:意外的令牌选项卡

[英]reactjs: Unexpected token Tabs

I'm trying to use react-tabs here https://github.com/reactjs/react-tabs to create tabs on my UI. 我试图在这里https://github.com/reactjs/react-tabs使用react-tabs在我的UI上创建选项卡。 This is my code so far: 到目前为止,这是我的代码:

index.jsx: index.jsx:

import React from 'react';
import ReactDOM from 'react-dom';
import TabsApp from './TabsApp.jsx';

main();

function main() {
    render(<TabsApp/>, document.getElementById('container'));
}

And this is my TabsApp.jsx: 这是我的TabsApp.jsx:

import React, { Component } from 'react';
import { render } from 'react-dom';
import { Tab, Tabs, TabList, TabPanel } from 'react-tabs';

class TabsApp extends Component {
  handleSelect(index, last) {
    console.log('Selected tab: ' + index + ', Last tab: ' + last);
  }

  render() {
    return (
      {}

      <Tabs
        onSelect={this.handleSelect}
        selectedIndex={2}
      >

        {}

        <TabList>

          {}

          <Tab>Foo</Tab>
          <Tab>Bar</Tab>
          <Tab>Baz</Tab>
        </TabList>

        {}

        <TabPanel>
          <h2>Hello from Foo</h2>
        </TabPanel>
        <TabPanel>
          <h2>Hello from Bar</h2>
        </TabPanel>
        <TabPanel>
          <h2>Hello from Baz</h2>
        </TabPanel>
      </Tabs>
    );
  }
}

But this is the error I'm getting: 但这是我得到的错误:

 ERROR in ./TabsApp.jsx Module build failed: SyntaxError: C:/x/TabsApp.jsx: Unexpected token (14:8) <Tabs onSelect={this.handleSelect} selectedIndex={2} > 

Can anyone please help me? 谁能帮帮我吗?

I'm using webpack dev server. 我正在使用webpack开发服务器。 And 0.14.7 react 与0.14.7反应

Looks like your issue is in index.jsx. 看来您的问题在index.jsx中。 You are not using react to render the component. 您没有使用react渲染组件。 Your index.jsx should look like : 您的index.jsx应该如下所示:

import React from 'react';
import ReactDOM from 'react-dom';
import TabsApp from './TabsApp.jsx';

ReactDOM.render(
  <TabsApp />,
  document.getElementById('container')
);

You've got 你有

  render() {
    return (
      {}

      <Tabs

Get rid of that random {} there. 摆脱那里的随机{} You can't return an empty object AND a <Tabs> component. 您不能返回空对象和<Tabs>组件。

erichardson30 is also correct... that's another problem. erichardson30也是正确的……这是另一个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM