mardi 7 juillet 2020

Clear checkbox in reactjs hooks after submitting

I have a few separate checkboxes in a form. But I have no idea how I could clear the checkboxes after submitting it.

const App = () =>{

   const funct1 = (e) => {
      //some function
   }

   const funct2 = (e) => {
      //some function
   }

   const funct3 = (e) => {
      //some function
   }
   const submitForm= (e) => {
      //some function
   }
   
   return(
      <div>
         <div>
            Pear <Checkbox onChange={(e)=>funct1(e)} />
         </div>
         <div>
            Apple <Checkbox onChange={(e)=>funct2(e)} />
         </div>
         <div>
            Orange <Checkbox onChange={(e)=>funct3(e)} />
         </div>
         <Button onClick={(e) => submitForm(e)}> Submit </Button>
      </div>
   )
}

I have read about useRef, but I am not sure how it can help me in this situation. Can anyone explains to me if it is possible to use useRef in this situation to help me achieve what I wanted?




Aucun commentaire:

Enregistrer un commentaire