Question 1 / 1
A developer writes the following StarRating component:
class StarRating extends React.Component {
constructor(props) {
super(props)
this.state = { starsSelected: 0 }
}
change(starsSelected) {
this.state.starsSelected = starsSelected
}
render() {
const { totalStars } = this.props
const { starsSelected } = this.state
return (
<div>
{[...Array(totalStars)].map((n, i) => (
<Star key={i}
selected={i < starsSelected}
onClick={() => this.change(i + 1)}
/>
))}
<p>{starsSelected} of {totalStars} stars</p>
</div>
)
}
}
The user clicks stars but the display never updates. What is the root cause?