There’s a state here, brushSize which is adjusted using a slider. It goes as props to another component, Board. However, the render function keeps executing before the state is able to change, and Board ends up getting the old value. I was able to confirm this by checking the received props value in Board.js, which is the old value.
According to what I could find, render() is supposed to execute once the state has changed, but that doesn’t seem to be happening.
import React from 'react'
import Board from './Board'
import './style.css'
class Container extends React.Component {
constructor(props) {
super(props);
this.state = {brushSize: 2};
this.brushSizeChange = this.brushSizeChange.bind(this);
}
brushSizeChange(e) {
this.setState((prev) => { return { ...prev, brushSize: e.target.value } });
}
render() {
return (
<div className="container">
<label>Brush size: </label>
<input type="range" min="1" max="10" value={this.state.brushSize} onChange={this.brushSizeChange} />
<h1>placeholder</h1>
<div className="board-container">
<Board size={this.state.brushSize}/>
</div>
</div>
)
}
}
export default Container