我尝试在https://github.com/reactjs/react-tabs使用react-tabs在我的UI上创建标签。到目前为止,这是我的代码:
index.jsx:
import React from 'react';
import ReactDOM from 'react-dom';
import TabsApp from './TabsApp.jsx';
main();
function main() {
render(<TabsApp/>, document.getElementById('container'));
}
这是我的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>
);
}
}
但这是我得到的错误:
ERROR in ./TabsApp.jsx Module build failed: SyntaxError: C:/x/TabsApp.jsx: Unexpected token (14:8) <Tabs onSelect={this.handleSelect} selectedIndex={2} >
有人可以帮助我吗?
我正在使用webpack dev服务器。和0.14.7反应
答案 0 :(得分:2)
看起来你的问题在index.jsx中。您没有使用react来呈现组件。您的index.jsx应如下所示:
import React from 'react';
import ReactDOM from 'react-dom';
import TabsApp from './TabsApp.jsx';
ReactDOM.render(
<TabsApp />,
document.getElementById('container')
);
答案 1 :(得分:1)