reactjs - 未捕获的类型错误:sweetalert2_react_content_1.default 不是函数
问题描述
我有一个使用 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>
})
解决方案
这是已知问题,您可以在此处订阅:https ://github.com/sweetalert2/sweetalert2-react-content/issues/102
作为一种解决方法,SweetAlertOptions
用于传递参数:
MySwal.fire({
title: <p>Holahola</p>
});
推荐阅读
- java - playbook 需要检查 java 版本,如果 java 版本低于 1.8* 版本,则 playbook 安装 java 1.8*
- mongodb - MongoDB:在多文档事务中计算文档
- javascript - 从 onclick 属性将 javascript 数组传递给函数
- tensorflow - Google Cloud AISE TensorFlow NVidia GPU 生产 - tensorflow 看不到 GPU
- mysql - 得到一个mysql请求的答案
- reactjs - 所有组件的 React Common 配置文件
- java - 除非使用 Autowired 注解,否则 Spring Boot 应用程序无法实例化一个类
- ios - 快速多选搜索
- java - JPA NativeQuery Get ResultList 中的未检查分配警告
- c++ - 如何正确声明子类?(C++)