未捕获的TypeError:sweetalert2_react_content_1。默认不是函数

问题描述 投票:1回答:1

我有一个React模块,我正在使用TypeScript。

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

这是我的代码:

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

const MySwal = withReactContent(Swal);

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

[当我将鼠标悬停在“ Holahola”时,我收到错误消息:“类型'Element'与类型'SweetAlertOptions'.ts(2769)没有共同的属性”。

[当我尝试在Chrome中运行我的代码时,我得到:“ Uncaught TypeError:swealert2_react_content_1.default不是函数”

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

reactjs typescript react-hooks sweetalert2
1个回答
0
投票

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

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

MySwal.fire({ 
  title: <p>Holahola</p> 
});
© www.soinside.com 2019 - 2024. All rights reserved.