es6/7 React14 中的 StaticProptypes
StaticProptypes in es6/7 React14
static propTypes: {
arrayOfLines: PropTypes.arrayOf(PropTypes.number)
};
at arrayOf( < at that paren 它给了我语法错误,但查看文档似乎应该是正确的
只做 PropTypes.array 似乎也能正常工作,或者 number
我的收录是这样的:
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 演示
根据 stage-1
提案,static
属性 之后是 =
而不是 :
static propTypes = {
arrayOfLines: PropTypes.arrayOf(PropTypes.number)
};
参考文献:
static propTypes: {
arrayOfLines: PropTypes.arrayOf(PropTypes.number)
};
at arrayOf( < at that paren 它给了我语法错误,但查看文档似乎应该是正确的 只做 PropTypes.array 似乎也能正常工作,或者 number
我的收录是这样的:
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 演示
根据 stage-1
提案,static
属性 之后是 =
而不是 :
static propTypes = {
arrayOfLines: PropTypes.arrayOf(PropTypes.number)
};
参考文献: