Home > Mobile >  How to disable a button after it gets pressed? React Native
How to disable a button after it gets pressed? React Native

Time:10-08

How can I disable a button after it gets pressed once in a functional component??

Here's my code:

 const Verify = () => {
    firebase
      .auth()
      .currentUser.sendEmailVerification()
      .then(() => {
        Alert.alert(
            'Code Sent')
      });
  };

 <Button onPress={() => Verify();} />

CodePudding user response:

You can use the prop disabled as mentioned in the docs here

const [isDisabled, setDisabled] = useState(false)
<Button onPress={() => Verify();} disabled={isDisabled} />

In your Verify function, you can set the isDisabled as true

setDisabled(true)
  • Related