Search code examples
reactjsecmascript-6react-dnd

StaticProptypes in es6/7 React14


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

at arrayOf( < at that paren it gives me a syntax error, but looking at the docs it seems like it should be right doing just PropTypes.array seems to work fine too, or number

My includes are this:

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>
        );
    }

}

this is actually just from the reactdnd demo


Solution

  • As per the stage-1 proposal the static property is followed by = not :

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

    References: