export default decreasePrice extends React.Component {
constructor(props) {
super(props);
this.state = {
price : 50000
}
};
_handlePrice = () => {
this.setState({price : this.state.price - 2000});
}
render() {
return( <div>
<TouchableOpacity onPress={this._handlePrice} >
<Text> Offer for you </Text>
</TouchableOpacity>
)
}}
So , what I want is, I want to disable my button after oneclick once price is decresed , so that user can not decrese price again and again. I want to disable the button after oneCLick.
you can use a variable as flag, for example this.pressed:
export default decreasePrice extends React.Component {
constructor(props) {
super(props);
this.pressed = false;
this.state = {
price : 50000
}
};
_handlePrice = () => {
if (!this.pressed){
this.pressed = true;
this.setState({price : this.state.price - 2000});
}
}
render() {
return(
<TouchableOpacity onPress={this._handlePrice} >
<Text> Offer for you </Text>
</TouchableOpacity>
)
}
}
in this way button just working for one time. you alse can remove TouchableOpacity after press:
render() {
if (!this.pressed)
return(
<TouchableOpacity onPress={this._handlePrice} >
<Text> Offer for you </Text>
</TouchableOpacity>
)
else
return(
<View>
<Text> Offer for you </Text>
</View>
)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With