Anaïs Saez
Anaïs Saez

Reputation: 1339

Checkbox checked in React.js

I'm trying to use the javascript function .checked() in React.js like this :

componentDidMount () {
    document.getElementById("myCheck").checked = true;
}

But I have an error in my console : "la propriété 'checked' n'existe pas sur le type HTMLlement"

How can I use this in React.js ?

Thank you

Upvotes: 1

Views: 1970

Answers (1)

Alexandr Dobrovolsky
Alexandr Dobrovolsky

Reputation: 66

It worked for me

<div className='container'>
    <input type='checkbox' ref='myAwesomeCheckbox' id={'scales'} />
    <label fhtmlForor="scales">Scales</label>
</div>

componentDidMount = () => {
  this.refs.myAwesomeCheckbox.checked = true;
}

Upvotes: 1

Related Questions