Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

this keyword is returning true/false instead of element object in react/ react-native

$
0
0
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


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>