【发布时间】:2020-04-27 17:57:32
【问题描述】:
我似乎无法让我的 Swal2 React 内容正常工作。 我已经按照与此处指南相同的方式实现了它: https://www.npmjs.com/package/sweetalert2-react-content
虽然我在尝试调用该函数时不断在控制台中收到此错误:
Uncaught (in promise) TypeError: Cannot call a class as a function
at _classCallCheck (carousel.css:190)
at _class (carousel.css:190)
at File.tsx:34
我在 Typescript 中使用 Hooks(也尝试过使用类 - 同样的错误)。 有人知道我在这里做错了什么吗?我正在使用 Sweetalert2 和 Sweetalert2 React Content 的最新版本。
我的代码如下所示:
const SwalModal = withReactContent(Swal);
const File = (props: IProps) => {
const submitForm = (e: any) => {
e.preventDefault();
APIsubmitForm(props)
.then(response => {
//Set props
})
.catch(error => {
SwalModal({
title: <h1>Error</h1>,
html: <p>Errormessage</p>,
icon: "error",
onOpen: () => {
SwalModal.clickConfirm()
}
}).then(() => {
return SwalModal.fire("<p>Shorthand works too</p>")
});
});
};
......
【问题讨论】:
标签: reactjs typescript react-hooks sweetalert2