mocheng / react-and-redux

《深入浅出React和Redux》代码

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

2.3.1 getlnitialState和getDefaultProps错误

foxconn-quality-inspector opened this issue · comments

class Sample extends React.Component {
  constructor(props) {
    super(props);
    this.state = { foo: "’bar " };
  }
});
Sample.defaultProps = {
  return { sampleProp: 0 }
};

报错
正确:

class Sample extends React.Component {
  constructor(props) {
    super(props);
    this.state = { foo: "’bar " };
  }
}
Sample.defaultProps = {
  sampleProp: 0
};