I recently started learning/coding in react and I need help in fixing a bug. I have 2 checkboxes on my application screen but those checkboxes should work like radio button which means when I check one checkbox, other checkbox should automatically uncheck. I tried using below options but its returning true/false instead of element object
<View style={{ flexBasis: '50%' }}><PrimaryCheckBox onPress={this.toggleForPrimaryCheckBox} checkBoxValue='forPrimary' checkBoxLabel='forPrimary' checkBoxViewStyle={stylesheet.CheckboxViewStyle} checkBoxTextStyle={stylesheet.CheckboxTextStyle} /></View><View style={{ flexBasis: '50%' }}><PrimaryCheckBox onPress={() => this.toggleForDependentCheckBox.bind(this)} checkBoxValue='forDependent' checkBoxLabel='forDependent' } checkBoxViewStyle={ stylesheet.CheckboxViewStyle } checkBoxTextStyle={ stylesheet.CheckboxTextStyle } /></View>
Note: PrimaryCheckBox component is a custom component
I tried the below options and none worked
1. onPress={() => this.toggleForDependentCheckBox.bind(this)}2. onPress={this.toggleForDependentCheckBox.bind("forDependent",e)} //threw error that e is not defined3. onPress={this.toggleForDependentCheckBox} public toggleForPrimaryCheckBox = (e: MouseEvent) => { console.log(e); //returns true when checked and false when unchecked console.log(this) // returns class component }
Can someone please help what mistake I am doing?I am trying to use single function for both elements so that based on selected element, I can uncheck other element and perform other logic
<View style={{ flexBasis: '50%' }}><PrimaryCheckBox onPress={this.togglePrimaryDependentCheckBox} checkBoxValue='forPrimary' checkBoxLabel='forPrimary' checkBoxViewStyle={stylesheet.CheckboxViewStyle} checkBoxTextStyle={stylesheet.CheckboxTextStyle} /></View><View style={{ flexBasis: '50%' }}><PrimaryCheckBox onPress={this.togglePrimaryDependentCheckBox} checkBoxValue='forDependent' checkBoxLabel='forDependent' } checkBoxViewStyle={ stylesheet.CheckboxViewStyle } checkBoxTextStyle={ stylesheet.CheckboxTextStyle } /></View>
Thanks in advance