首页 > React不报错的情况下怎么调试?

React不报错的情况下怎么调试?

class Counter extends React.Component {
  constructor(props) {
    super(props);   
    this.state = {state: props.initialState};
    this.tick = this.tick.bind(this);
  }
  tick() {
    this.setState({state: this.state.state & 1});
  }
  render() {
    return (
      <div onClick={this.tick}>
        On: {this.state.state === '1'}
      </div>
    );
  }
}
Counter.propTypes = { initialState: React.PropTypes.number };
Counter.defaultProps = { initialState: 0 };

ReactDOM.render(
  <Counter />,
  document.getElementById('container')
);

这段代码并没有报错,但是运行后会没有初始状态:

显然是有错误的,但是不报错的情况下,应该怎么调试?谢谢……


Chrome上没安ReactDevtools吗,可以看到组建的state和props等等信息。

【热门文章】
【热门文章】