Reputation: 135
I am building a dice application where I have a class component for setting number of dice and number of sides of each dice. I pass these values into a child class component where I calculate the max score possible by multiplying number of dice with number of sides on each dice. In my parent class, there are methods for the user to change number of sides and number of dice. However, only initial value of dice and sides gets passed to the child and I do not know how to pass updated value to the child when state of the parent changes. I am new to React js so it might seem like a silly question.
Upvotes: 0
Views: 76
Reputation: 491
You weren't updating the state in the roll change function.
rollChange() {
this.setState({ maxScore: this.props.noOfSides * this.props.noOfDice });
}
When the state on the parent changes that triggers a render of the parent which will in turn re-render the Child component with the updated props.
Upvotes: 2