我有一个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不是函数”
有人知道这里发生了什么?
这是已知问题,您可以在这里订阅:https://github.com/sweetalert2/sweetalert2-react-content/issues/102
作为一种解决方法,请使用SweetAlertOptions
传递参数:
MySwal.fire({
title: <p>Holahola</p>
});