Answer the question
In order to leave comments, you need to log in
How to update a component depending on a function?
I'm completely confused, please help me figure it out.
There is a form. It uses radiobuttons - buttons, like switches. The active button has the active class. I need to display the degree of completion of the form, each button toggle uses the Set State. I also use refs. My idea is this: State has been changed, there is a life cycle of state change. Called: Component Did Update. We need it because we can get refs from the form here. In it, I count the selected answers, and I want to throw
this.setState({progress:active/((active+overs)/2)*100})
this.setState({progress:active/((active+overs)/2)*100})
shouldComponentUpdate (state.prev!=state.next)
progressForm(){
console.log(this.myRef)
var active=0;
var overs=0;
for(let i=0;i<this.myRef.current.length;i++){
console.log(this.myRef.current[i].className)
if (this.myRef.current[i].className.includes('active')){
active++;
}
else if (this.myRef.current[i].className.includes('btn'))
overs++;
}
this.setState({progress:active/((active+overs)/2)*100})
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question