When the parent component passes the value to the child component, the child component dynamically changes the state

Problem description:
In the process of learning react, the child component receives props of the parent component. At this time, I want to set the value passed by the parent component to the state of the child component.

Insert picture description here
After this error occurs, you can achieve this by putting setstate into componentWillReceiveProps hook

componentWillReceiveProps () {
console.log ('Component received new parameters') this.setState
({
value: this.props.value * 7
})
}

Published 5 original articles · Likes5 · Visits 117

Guess you like

Origin blog.csdn.net/qq_37061326/article/details/105533404