无法将箭头函数存储在React组件的let/var中 [英] Cannot store arrow function in let/var in React Component

查看:97
本文介绍了无法将箭头函数存储在React组件的let/var中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个组件由扩展 React.Component 定义.其中的内部以及render方法是:

I have a component in react defined by extends React.Component. Inside it, along with the render method, is:

constructor(props, context) {
    super(props, context);

    this.state = {
        open: false,
    };
}

handleClose = () => { //this works
    this.setState({open: false});
};

handleOpen = () => { //this works
    this.setState({open: true});
};

let empty = () => {}; // does not work, error  Parsing error:      Unexpected token

如果我在let或const的任何箭头函数前面加上前缀,我似乎会遇到意外的令牌错误.我在这里想念什么吗?

I seem to get an unexpected token error if I prefix any of the arrow functions with let or const. Am I missing something here?

谢谢

推荐答案

阅读 babel文档关于课程.使用letconst并不是类定义的ES6可能前缀的一部分

Read babel documentation about classes. using let or const is not part of ES6 possible prefix for classes definition

这篇关于无法将箭头函数存储在React组件的let/var中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆