You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Which means after you tap the checkbox, you get an error:
undefined is not an object (evaluating 'this.setState')
This error means you forgot to bind components context to your function = the handling function doesn't have access to the component's setState method.
You have to either bind context in the constructor, or use an arrow function:
importReactfrom"react";import{Block,Checkbox}from"galio-framework";exportdefaultclassAppextendsReact.Component<{}>{
state ={apples: false};handleOnChange=(val)=>{if(val){this.setState({apples: false});}else{this.setState({apples: true});}}render(){return(<Blocksafe><Checkboxlabel="Apples"flexDirection="row"initialValue={true}onChange={this.handleOnChange}/></Block>);}}
Describe the bug
When you pass the onChange function the checkbox stops changing state and stays either checked or unchecked.
If you remove onChange(), then it works but I cannot do anything based on if it was clicked or not. I think this.setState() is what is messing it up.
The text was updated successfully, but these errors were encountered: