Knows Not Much
Knows Not Much

Reputation: 31576

Invariant Violation: Minified React error #62

I wrote the following method inside a react component and everything works fine

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

But the 2 divs appear one on top of another. I changed my code to

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

But as soon as I put the style left and right. I get an error

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.

I don't understand this error at all.. why is the style='float:left' such a big deal?

Upvotes: 11

Views: 18423

Answers (1)

Agney
Agney

Reputation: 19224

Style expects a Javascript object of styles. What you have provided is a string.

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

From the documentation: https://reactjs.org/docs/dom-elements.html#style

Upvotes: 30

Related Questions