material ui checkbox checked not working

Solutions on MaxInterview for material ui checkbox checked not working by the best coders in the world

showing results for - "material ui checkbox checked not working"
Lya
10 Aug 2016
1// For me it was that I was using the wrong syntax for setting the state. 
2// Here is the correct way: 
3this.setState({checkedId});
4
5//Here is the way I was doing it which was wrong: 
6this.setState(checkedId);. 
7
8//Correcting this resolved the issue
9
10//Also if the SwitchBase component isn't aware of a change in the internal checkbox component.
11
12//The native checkbox element is being updated internally based on the checked attribute.
13//But by just setting the checked property, there will be no change event emitted.
14
15//You will have to dispatch a change event manually, but this needs you to override some React 
16//logic to make it work which I do not recommend.
17
18//Another possible solution would to be to wrap the checkbox in a component 
19//which holds the state of a single checkbox. By defining a setChecked 
20//method on the class component, you can call this method to change the 
21//checked state.
22
23//Check out this codesandbox: https:codesandbox.io/s/material-ui-u822z?fontsize=14&hidenavigation=1&theme=dark