装饰器功能不起作用(意外令牌) [英] Decorator feature not working (unexpected token)
本文介绍了装饰器功能不起作用(意外令牌)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只是试图在React中使用装饰器:
Just tried to use decorators in React:
import React from 'react';
import Fade from './Transitions/Fade'
import withVisible from './withVisible'
@withVisible()
const App = props =>
<Fade visible={props.visible} duration={500}>
Hello
</Fade>
export default App
如果我使用常见的方法(withVisible()(App)),那么它可以正常工作.(我的猜测是NodeJS无法使用@编译我的代码)[语法错误:意外的令牌(@)]
If I use the common way ( withVisible()(App) ) then it's working properly. (My guess is that NodeJS can't compile my code with the @ ) [Syntax error: Unexpected token (@) ]
import React from 'react'
const withVisible = () => Component =>
class WithVisible extends React.Component {
state = {
visible: true
}
render() {
return (
<Component visible={this.state.visible} {...this.props}/>
)
}
}
export default withVisible
推荐答案
您的.babelrc可能未添加装饰器插件.试试这个: https://babeljs.io/docs/plugins/transform-decorators
Probably your .babelrc do not have added decorator plugin. Try this: https://babeljs.io/docs/plugins/transform-decorators
这篇关于装饰器功能不起作用(意外令牌)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文