简体   繁体   English

onClick =()=> {在gulp中引发意外的令牌错误

[英]onClick = () => { throws unexpected token error in gulp

I tried to integrate a react component in my React project. 我试图将React组件集成到我的React项目中。 when transpiling with gulp I get an error on line onClick = () => { 用gulp进行编译时,我在onClick = () => {

js/expanding-animation.js: Unexpected token (14:16) js / expanding-animation.js:意外令牌(14:16)

I am using gulp with babelfy and "presets": ["react", "es2016"] 我将gulp与babelfy和"presets": ["react", "es2016"] presets "presets": ["react", "es2016"]一起使用"presets": ["react", "es2016"]

ideas? 想法?

 import React, {Component} from 'react';

    const animationStyle = {
        transition: 'width 0.75s cubic-bezier(0.000, 0.795, 0.000, 1.000)'
    };

    const makeExpanding = (Target) => {
        return class extends Component {
            constructor(props) {
                super(props);
                this.state = {isOpen: false};
            }

            onClick = () => {
                this.setState({isOpen: !this.state.isOpen});
            };

            render() {
                return (
                    <Target {...this.props}
                            isOpen={this.state.isOpen}
                            onClick={this.onClick}
                            additionalStyles={{text: animationStyle, frame: animationStyle}}/>
                );
            }
        }
    };

    export default makeExpanding;

This is an experimental feature. 这是一项实验功能。

You need to add babel stage-2 or just to enable this specific feature you can add the following transformation: http://babeljs.io/docs/plugins/transform-class-properties/ 您需要添加babel stage-2或仅启用此特定功能就可以添加以下转换: http : //babeljs.io/docs/plugins/transform-class-properties/

{
    "presets": ["react", "es2016"],
    "plugins": [
        "transform-class-properties"
    ]
}

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

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