Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
230 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...