vendredi 4 août 2017

Changing check value of checkbox without using setState but using ref attribute in React

I am selecting an input element using ref and then finally resetting each checked value to false(unchecking).We should be using setState but in my case its working as desired.So is there any deep drawback in doing so?

insertRow(event){
 .....
  let op,t,res='';
  for(let i=1;i<4;i++){
  op="op"+i;
  t=this.refs[op];
  res+=t.checked?t.value:'';
  t.checked=false;
                      }
.....
                } 

render(){
     return(<div>...
     <input key="1" ref="op1" type="checkbox" value="a"/>a) Dietary 
      Restrictions<br/>
      <input key="2"  ref="op2" type="checkbox" value="b"/>b) Physical 
      Disabilities<br/>
      <input key="3" ref="op3" type="checkbox" value="c"/>c) Medical 
      Needs<br/>
     </div>
       }




Aucun commentaire:

Enregistrer un commentaire