Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
228 views
in Technique[技术] by (71.8m points)

javascript - I want an alert message. Enter your name the click on button like add. If the textplace is empty its shows an error message

        <Button onClick={handleClick} 
                variant="contained" size="medium"
                style={{backgroundColor:"#4CB04F", color:"white" }} >
            Accept
        </Button>
      
        <Snackbar
         anchorOrigin={{
          vertical: "bottom",
          horizontal: "right",
        }}
          open={open} autoHideDuration={3000} onClose={handleClose}
        >
          <Alert
            onClose={handleClose}
            severity="success"
            
          >
            The file has been Uploaded Successfully
          </Alert>
          
        </Snackbar>
question from:https://stackoverflow.com/questions/65935495/i-want-an-alert-message-enter-your-name-the-click-on-button-like-add-if-the-te

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You are using the Snackbar component from React Native Paper. If you look at the docs here, you will notice the Snackbar already is an alert, and you should not be adding another Alert inside it.

  <Snackbar
    visible={visible}
    onDismiss={onDismissSnackBar}
    action={{
      label: 'Undo',
      onPress: () => {
        // Do something
      },
    }}>
    The file has been Uploaded Successfully
  </Snackbar>

In that same example you will find a Button component:

<Button onPress={onToggleSnackBar}>{visible ? 'Hide' : 'Show'}</Button>

This button has an onToggleSnackBar function. This is where you should check if the text area is empty or not.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...