Answer the question
In order to leave comments, you need to log in
How to force a React class to restart render( )?
How to force react to restart render?
props is received from the parent class
tried using this.forceUpdate() doesn't work or I'm not using it correctly
componentDidUpdate(prevProps, prevState) {
if(this.props.resetRender === true){
console.log(this.props.resetRender) // true
this.forceUpdate()
}
}
Answer the question
In order to leave comments, you need to log in
after render, componentDidUpdate is called in which you call render, after which componentDidUpdate is called in which ... I think the idea is clear.
If you need to re-render the component when the parent changes resetRender to true, move this code to 'componentWillUpdate'
In general, the parent should not force the render in this way. If you really want to - make a method and pull it from the parent where you need it directly. or just yank child.forceUpdate(). It will be just as bad, but a little less perversion and will work like clockwork. rerender () { this.forceUpdate() }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question