Reactjs 正在将getDefaultProps重构到ES6。。。什么';我的代码怎么了?
我有以下Reactjs 正在将getDefaultProps重构到ES6。。。什么';我的代码怎么了?,reactjs,ecmascript-6,Reactjs,Ecmascript 6,我有以下React.createClass,我想把它传递给扩展React.Component: var Rect = React.createClass({ getDefaultProps: function() { return { width: 0, height: 0, x: 0, y: 0 }
React.createClass
,我想把它传递给扩展React.Component
:
var Rect = React.createClass({
getDefaultProps: function() {
return {
width: 0,
height: 0,
x: 0,
y: 0
}
},
render: function() {
return (
<rect className="bar"
height={this.props.height}
y={this.props.y}
width={this.props.width}
x={this.props.x}
>
</rect>
);
},
});
var Rect=React.createClass({
getDefaultProps:function(){
返回{
宽度:0,
高度:0,,
x:0,,
y:0
}
},
render:function(){
返回(
);
},
});
我打了一针,但没用:
class Rect extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<rect className="bar"
height={this.props.height}
y={this.props.y}
width={this.props.width}
x={this.props.x}
>
</rect>
);
}
Rect.defaultProps = {
width: 0,
height: 0,
x: 0,
y: 0
}
};
类Rect扩展React.Component{
建造师(道具){
超级(道具);
}
render(){
返回(
);
}
Rect.defaultProps={
宽度:0,
高度:0,,
x:0,,
y:0
}
};
那怎么了 在这种情况下,
defaultProps
定义需要在类定义之外:
class Rect extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<rect className="bar"
height={this.props.height}
y={this.props.y}
width={this.props.width}
x={this.props.x}
>
</rect>
);
}
};
Rect.defaultProps = {
width: 0,
height: 0,
x: 0,
y: 0
}
类Rect扩展React.Component{
建造师(道具){
超级(道具);
}
render(){
返回(
);
}
};
Rect.defaultProps={
宽度:0,
高度:0,,
x:0,,
y:0
}
在这种情况下,defaultProps
定义需要在类定义之外:
class Rect extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<rect className="bar"
height={this.props.height}
y={this.props.y}
width={this.props.width}
x={this.props.x}
>
</rect>
);
}
};
Rect.defaultProps = {
width: 0,
height: 0,
x: 0,
y: 0
}
类Rect扩展React.Component{
建造师(道具){
超级(道具);
}
render(){
返回(
);
}
};
Rect.defaultProps={
宽度:0,
高度:0,,
x:0,,
y:0
}