gpt4 book ai didi

reactjs - 不变违规 : Minified React error #62

转载 作者:行者123 更新时间:2023-12-03 13:40:07 35 4
gpt4 key购买 nike

我在 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>
)}

但是 2 个 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.

我根本不明白这个错误..为什么 style='float:left' 这么重要?

最佳答案

Style 需要一个 Javascript 样式对象。您提供的是一个字符串。

<div style={{float: 'right'}}>
<ScoreBoard correct={this.state.correct} incorrect={this.state.incorrect} />
</div>

来自文档:https://reactjs.org/docs/dom-elements.html#style

关于reactjs - 不变违规 : Minified React error #62,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48897903/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com