Meteor7静态原型还没有被Meteor支持,有什么好的解决方法? [英] ECMA7 static prototypes is not yet supported in Meteor, what is a good workaround?

查看:163
本文介绍了Meteor7静态原型还没有被Meteor支持,有什么好的解决方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的React代码中使用ECMA静态proptypes。不幸的是,这会抛出以下Babel错误
缺少类属性转换。。据我所知,这是因为Meteor尚未支持第0阶段的ECMA提案。



从阅读各种线程看来,似乎可能会通过修改一些巴贝尔配置,但是我不太熟悉巴别塔,所以宁可避免拧紧它。如何以另一种支持的方式表达下面的静态/ proptypes逻辑?



谢谢!

  import来自'react'的反应; 
从../Kooks/Table/BookSingleLine导入bookSingleLine;
导入TrackerReact from'meteor / ultimatejs:tracker-react';


导出默认类bookListingTable extends TrackerReact(React.Component){

static propTypes = {
LimitProp:React.PropTypes.number.isRequired
}
static defaultProps = {
LimitProp:5,
}


解决方案

只需手动分配静态属性,而不是在类体中声明它们(在ES7中不支持):

  export default class BookListingTable extends TrackerReact(React.Component){
...
}
BookListingTable.propTypes = {
LimitProp:React。 PropTypes.number.isRequired
};
BookListingTable.defaultProps = {
LimitProp:5
};


I would like to use ECMA static proptypes within my React code. Unfortunately this throws the following Babel error Missing class properties transform.. As far as I'm aware this is because Meteor does not yet support stage 0 ECMA proposals.

From reading various threads it seems like it may be possible to resolve this by amending some babel configs, however I'm not too familiar with Babel so would rather avoid screwing with it too much. How can I express the below static /proptypes logic in an alternative, supported fashion?

Thanks!

import React from 'react';
import bookSingleLine from '../Kooks/Table/BookSingleLine';
import TrackerReact from 'meteor/ultimatejs:tracker-react';


export default class bookListingTable extends TrackerReact(React.Component) {

static propTypes = {
LimitProp: React.PropTypes.number.isRequired
  }
static defaultProps ={
    LimitProp: 5,
  }

解决方案

Just manually assign the static properties instead of declaring them in the class body (which is not supported in ES7):

export default class BookListingTable extends TrackerReact(React.Component) {
    …
}
BookListingTable.propTypes = {
    LimitProp: React.PropTypes.number.isRequired
};
BookListingTable.defaultProps = {
    LimitProp: 5
};

这篇关于Meteor7静态原型还没有被Meteor支持,有什么好的解决方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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