mercredi 17 mars 2021

How to Call method default on checked or default checked attribute in react functional component only

Hello I'm new in React so I'm trying to call function because I want to show checked mark on checkbox condition so I want to checkbox is checked on some condition.

I tried below code but it's not calling

HTML

<input type="checkbox" className="form-check-input" id="wifi" defaultChecked={(name,value) => 
checkIt(name,value)} value={checkbox.wifi} /> // Here i removed onChange event because that method work i mean functionality work

<label className="form-check-label" htmlFor="wifi">Free Wifi</label>

JS

const checkIt = (name, value) => {
        console.log(`
            name : ${name},
            value : ${value}
       `)
 }

MY EXPECTATION : checkIt this method call on load by default in react with funtional component only i want that name and value and thanks for your answer.




Aucun commentaire:

Enregistrer un commentaire