const [checked, checkedState] =useState(null)
const handleClick = () =>{
checkedState(false)
}
<div className='radiobtn'>
<input type="radio" value={5} name="discount" checked={checked} id="five" />
<label htmlFor="five">5%</label>
</div>
<div className='radiobtn'>
<input type="radio" value={10} name="discount" checked={checked} id="ten"/>
<label htmlFor="ten">10%</label>
</div>
<div className='radiobtn'>
<input type="radio" value={15} name="discount" checked={checked} id="fifteen"/>
<label htmlFor="fifteen">15%</label>
</div>
<div className='radiobtn'>
<input type="radio" value={25} name="discount" checked={checked} id="twentyfive"/>
<label htmlFor="twentyfive" >25%</label>
</div>
<div className='radiobtn'>
<input type="radio" value={50} name="discount" checked={checked} id="fifty" />
<label htmlFor="fifty">50%</label>
</div>
<button onClick={()=>handleClick()}>reset</button>
i used the useState to uncheck all the radio button but then the radio button dont chnage at all when clicked again because they are all false. Am i forgetting something ? I tried using null
value in useState
but it give Warning: A component is changing an uncontrolled input to be controlled.