【问题标题】:StaticProptypes in es6/7 React14es6/7 React14 中的静态属性
【发布时间】:2015-12-04 22:57:26
【问题描述】:
static propTypes: {
        arrayOfLines: PropTypes.arrayOf(PropTypes.number)
    };

at arrayOf(

我的包括:

import React, {Component, PropTypes} from 'react';
import ReactDOM from 'react-dom';
import CodeLine from './CodeLine';
import GridSpace from './GridSpace';

export default class Grid extends React.Component{

    static propTypes: {
        arrayOfLines: PropTypes.arrayOf(PropTypes.number)
    };

    renderGridSpace(x,y) {
        const gray = (x + y) % 2 === 1;

        const [spaceX, spaceY] = this.props.arrayOfLines
    }

    render() {
        const { gray } = this.props;
        const fill = gray ? 'gray' : 'white';
        const stroke = gray ? 'white' : 'gray';
        console.log(PropTypes);
        return (
            <div style={{ 
            backgroundColor: fill,
            color: stroke,
            width: '100%',
            height: '100%'
             }} >
                {this.props.children}
            </div>
        );
    }

}

这实际上只是来自 reactdnd 演示

【问题讨论】:

  • 什么给你语法错误?你在使用转译器吗?您是否检查过以确保它理解此语法并且已对其进行配置?
  • static propTypes = {} = 而不是:

标签: reactjs ecmascript-6 react-dnd


【解决方案1】:

根据stage-1 提案,static 属性后跟= 而不是:

static propTypes = {
    arrayOfLines: PropTypes.arrayOf(PropTypes.number)
};

参考资料:

【讨论】:

    猜你喜欢
    • 2016-01-11
    • 2017-10-20
    • 2017-06-07
    • 2016-11-16
    • 2018-04-18
    • 2018-06-09
    • 1970-01-01
    • 1970-01-01
    • 2014-12-21
    相关资源
    最近更新 更多