繁体   English   中英

如何显示脉轮 UI '警报'?

[英]How to display the Chakra UI 'Alert'?

我正在尝试使用 Chakra Ui 显示警报消息,但它没有显示。 请帮忙。

.catch((error) => {
            const errorCode = error.code;
            const errorMessage = error.message;
            console.log(errorMessage, errorCode);
            <Alert status='error'>
                <AlertIcon />
                <AlertTitle>Error!</AlertTitle>
                <AlertDescription>Email/ Password Did Not Matched.</AlertDescription>
            </Alert>
        });

<Alert />之类的组件不能添加到 Promise 的捕获中。 您必须有条件地在组件的 return 语句中呈现警报,如下所示:

 function LoginExample() { const [showAlert, setShowAlert] = useState(false) const handleLogin = (email, password) => { loginUser(email, password) .then((res) => /* handle success */) .catch((error) => { const errorCode = error.code; const errorMessage = error.message; console.log(errorMessage, errorCode); setShowAlert(true) }) } return ( <> {showAlert && ( <Alert status='error'> <AlertIcon /> <AlertTitle>Error!</AlertTitle> <AlertDescription>Email/ Password Did Not Matched.</AlertDescription> </Alert> )} {/* rest of jsx */} </> ) }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM