I'm currently working on an app that features various games. My goal is to allow users to click a button and have the game display on the screen, with the background color changing as well. I aim to utilize state to control the overall background of the entire app, not just the game component.
However, I'm encountering an issue where the state changes when the game is displayed, but the page does not update accordingly. Any suggestions?
Here's a glimpse of my current state setup:
state = {
madLibsOut: false,
ticTacOut: false,
pigLatinOut: false,
background: "green",
}
Below is an example of my attempt to make a change. Although the state updates successfully and the game is displayed, the background color fails to update:
handleClickTicTacToe = () => {
const out = this.state.ticTacOut
const newColor = 'red'
this.setState({ ticTacOut: true, background: newColor })
}
For reference, here's how I am applying the style:
appStyle={
backgroundColor: this.state.background,
height: "100vh",
width: "100%",
}
render() {
return (
<div className="App" style={this.appStyle}>
Any help or advice would be greatly appreciated. Thank you!