Skip to content

Instantly share code, notes, and snippets.

@aditodkar
Created February 13, 2019 15:38
Show Gist options
  • Save aditodkar/9607d25fba8386566c1249591b0791bc to your computer and use it in GitHub Desktop.
Save aditodkar/9607d25fba8386566c1249591b0791bc to your computer and use it in GitHub Desktop.
constructor(props) {
super(props);
this.state = {
BHKtype: []
};
}
filterItems = (value, type) => {
console.log("Value: ", value);
console.log("Type: ", type);
switch (type) {
case '1 BHK':
if(this.state.BHKtype.includes(value) === false){
this.setState( prevState => ({
BHKtype: [...prevState.BHKtype, value]
}));
}
break;
case '2 BHK':
if(this.state.BHKtype.includes(value) === false){
this.setState( prevState => ({
BHKtype: [...prevState.BHKtype, value]
}));
}
break;
case '3 BHK':
if(this.state.BHKtype.includes(value) === false){
this.setState( prevState => ({
BHKtype: [...prevState.BHKtype, value]
}));
}
break;
case '3+ BHK':
if(this.state.BHKtype.includes(value) === false){
this.setState( prevState => ({
BHKtype: [...prevState.BHKtype, value]
}));
}
break;
default:
break;
}
}
<View style={styles.buttonContainer}>
<TouchableOpacity onPress={() => this.filterItems(1, "1 BHK")}>
<Filterbutton name="1 BHK" checked={this.state.BHKtype.includes(1)}/>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.filterItems(2, "2 BHK")}>
<Filterbutton name="2 BHK"/>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.filterItems(3, "3 BHK")}>
<Filterbutton name="3 BHK"/>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.filterItems(4, "3+ BHK")}>
<Filterbutton name="3+ BHK"/>
</TouchableOpacity>
</View>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment