I have an issue with Switch component from react native, the issue is user able to multiple click on switch component before API completed. So, how to prevent user to multiple click on switch component?
I’m using class component btw.
<Switch
trackColor={{ false: MONOCHROME_5, true: POLYCHROME_1 }}
ios_backgroundColor={MONOCHROME_5}
onValueChange={() => {
//do something
}}
onChange={(e) => console.log(e)}
value={this.state.enabled}
/>
Already try to use state to disable the component with onTouchStart props, but it was still able to multiple click
2
Answers
I got the answer from my partner
here is the way
it was almost same with concept from @Stitt, but we found out how to prevent double click from iOS and android device
Use a
useState
hook to hold the state of a boolean value which will set the switch’sdisabled
prop. You can then toggle this boolean in youronChange
oronValueChange
function to disable the switch, and then re-enable once the API call has completed.