我在react组件中编写了以下方法,一切正常
render() { return (
<div>
<div>
<AppHeader x = {this.state.x} y = {this.state.y} />
<Button id = {0} x = {this.state.x} y = {this.state.y} answerKey = {this.state.answerKey} handleClick={this.handleClick} />
<Button id = {1} x = {this.state.x} y = {this.state.y} answerKey = {this.state.answerKey} handleClick={this.handleClick} />
<Button id = {2} x = {this.state.x} y = {this.state.y} answerKey = {this.state.answerKey} handleClick={this.handleClick} />
<Button id = {3} x = {this.state.x} y = {this.state.y} answerKey = {this.state.answerKey} handleClick={this.handleClick} />
</div>
<div>
<ScoreBoard correct={this.state.correct} incorrect={this.state.incorrect} />
</div>
</div>
)}
但是这两个div在另一个上面显示出来。我将代码更改为
render() { return (
<div>
<div style='float:left'>
<AppHeader x = {this.state.x} y = {this.state.y} />
<Button id = {0} x = {this.state.x} y = {this.state.y} answerKey = {this.state.answerKey} handleClick={this.handleClick} />
<Button id = {1} x = {this.state.x} y = {this.state.y} answerKey = {this.state.answerKey} handleClick={this.handleClick} />
<Button id = {2} x = {this.state.x} y = {this.state.y} answerKey = {this.state.answerKey} handleClick={this.handleClick} />
<Button id = {3} x = {this.state.x} y = {this.state.y} answerKey = {this.state.answerKey} handleClick={this.handleClick} />
</div>
<div style='float:right'>
<ScoreBoard correct={this.state.correct} incorrect={this.state.incorrect} />
</div>
</div>
)}
但是一旦我把风格左右。我收到错误
Invariant Violation: Minified React error #62; visit http://facebook.github.io/react/docs/error-decoder.html?invariant=62&args[]=%20This%20DOM%20node%20was%20rendered%20by%20%60Quiz%60. for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
我根本不理解这个错误。为什么风格=&#39;浮动:左边&#39;这么大的一笔?
答案 0 :(得分:6)
Style需要一个样式的Javascript对象。你提供的是一个字符串。
<div style={{float: 'right'}}>
<ScoreBoard correct={this.state.correct} incorrect={this.state.incorrect} />
</div>