Reputation: 1339
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
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