I am working on a react project I am trying to checked checkbox using state in react, but Unable to do it After I checked checkbox using state. I need to change state using setState. For example If I have checked using state then when I click the checkbox, then it has to change its state to checked: false.
If I am not clear put a comment.
This is code
This is App.js
import React, { Component } from 'react';
export default class App extends Component {
constructor(props) {
super(props)
this.state = {
checked: true
}
}
render() {
return (
<div>
<form>
<div class="form-group form-check">
<input style ={{defaultChecked: this.state.checked}} type="checkbox" class="form-check-input" id="exampleCheck1" />
</div>
</form>
</div>
)
}
}
checkedattribute of<input>rather thanstyle?onChange()event handler to dosetState()