【问题标题】:Uncaught TypeError: sweetalert2_react_content_1.default is not a function未捕获的类型错误:sweetalert2_react_content_1.default 不是函数
【发布时间】:2020-04-04 00:02:14
【问题描述】:

我有一个使用 TypeScript 的反应模块。

我想在 Swal 组件中使用 html,但那是行不通的。

这是我的代码:

import Swal from "sweetalert2";
import withReactContent from "sweetalert2-react-content";

const MySwal = withReactContent(Swal);

MySwal.fire(<p>Holahola</p>);

当我将鼠标悬停在“Holahola”上时,我收到错误消息:“类型‘元素’没有与类型‘SweetAlertOptions’.ts(2769) 相同的属性”。

当我尝试在 Chrome 中运行我的代码时,我得到:“Uncaught TypeError: sweetalert2_react_content_1.default is not a function”

有人知道这里发生了什么吗?

我也试过了:

MySwal.fire({
    title: <p>Holahola</p>
})

然后我得到这个错误:

【问题讨论】:

    标签: reactjs typescript react-hooks sweetalert2


    【解决方案1】:

    这是已知问题,您可以在这里订阅:https://github.com/sweetalert2/sweetalert2-react-content/issues/102

    作为一种解决方法,使用SweetAlertOptions 传递参数:

    MySwal.fire({ 
      title: <p>Holahola</p> 
    });
    

    【讨论】:

    • 我试过这个。请参阅上面的更新帖子。好像它不能处理 JSX 元素?
    • 似乎您需要将您的部门升级到最新版本:)
    • 我们正在使用最新版本的 sweetalert2 和 sweetalert2-react-content 以及 react 16.8.6 和 react-dom 16.8.6。我不明白这怎么可能是这样的问题?
    • 不,你没有。找出您的屏幕截图和github.com/sweetalert2/sweetalert2/blob/master/… 之间的区别
    • 对不起。你是对的。但是现在我已经安装了最新的 sweetalert2,重新安装了所有的 npm 包,我的 sweetalert2.d.ts 和你的一模一样。仍然收到错误消息(请参阅更新后的帖子)
    猜你喜欢
    • 1970-01-01
    • 2018-11-29
    • 1970-01-01
    • 1970-01-01
    • 2022-11-19
    • 1970-01-01
    • 2019-06-06
    • 2019-05-24
    • 2021-12-15
    相关资源
    最近更新 更多