As the title,
I want to set checkbox "checked" by default when the page was fully load,
but in the tutorial about Material-UI Checkbox component,
didn't have the defaultChecked props.
When I add checked={true} props, then get arror
like
"A component is changing an uncontrolled input of type checkbox to be controlled...etc"
How should I do?
there is my code
I want to list all the group, include the default group and the other
let the user to choose multi group.
export default class AcceptButton extends Component {
constructor(props) {
super(props)
this.handleChange = this.handleChange.bind(this)
this.state = {open: true}
}
handleChange = event => {
this.setState({checked: event.target.checked})
}
render() {
return (
<Fragment>
<div>
group :
</div>
<div className="f-col">
{
group.data.map(g => {
if (data.filter(d => d.gid == g.gid).length != 0) {
return (
<FormControlLabel
key={g.gid}
control={
<Checkbox
disabled={true}
onChange = {this.handleChange}
color="primary"
checked={this.state.open}
/>
}
label={g.gname}
/>
)}
else {
return (
<FormControlLabel
key={g.gid}
control={
<Checkbox
onChange={this.handleChange}
value={g.gname}
color="primary"
/>
}
label={g.gname}
/>
)}
})
}
</div>
<button className="btn" onClick={this.postassignhandle}>update</button>
</Fragment>
)