【发布时间】:2017-11-02 16:57:48
【问题描述】:
我有一个使用 reactjs 的项目,由 babel 转译。我使用 es2015 并在我的 .babelrc 中做出反应转换。我目前正在重构,在我的第一遍中,我基本上为我需要的一切做了export class foo。很多这些类实际上应该只是函数,所以我试图重写它们,但我一直收到同样的错误。我的主应用程序文件如下所示:
import React, { Component } from 'react';
import {Foo, Bar} from './components/ui.js';
class Application extends Component {
constructor(props){
super(props);
this.state = {
object: null
}
}
componentDidMount(){
// code
}
componentDidUpdate(){
// other code
}
render(){
return(
<div>
<Foo />
<Bar />
</div>
)
}
}
module.exports = Application
而我从ui.js 的导入是这样的:
import React, { Component } from 'react';
export class Foo extends Component {
constructor(props){
super(props);
}
render() {
return (
// Some JSX
)
}
}
export class Bar extends Component {
constructor(props){
super(props);
}
render() {
return (
// Some other JSX
)
}
}
当我尝试将这些导出的类之一更改为函数时,例如:
// Note: I have tried a variety of syntax such as function, const, etc...
export var Bar {
render() {
return (
// Some other JSX
)
}
}
我收到以下错误:
SyntaxError: Unexpected token <line where I declare a function>
我不知道我做错了什么,我的谷歌搜索只能找到其他问题的答案。
【问题讨论】:
标签: javascript reactjs ecmascript-6 babeljs