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?
Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
#185 text: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With