reactjs - 警告:“对象”类型的道具类型失败,应为字符串
问题描述
我正在使用 react/redux 构建一个应用程序,并且我已经安装了一个名为“reactconfirmalert”的 npm 包。这很好用,但是在我的控制台中,当我显示确认警报时,我得到了错误消息:
https://i.stack.imgur.com/eXJI0.png
以下是触发警报的代码:
import { confirmAlert } from 'react-confirm-alert';
import 'react-confirm-alert/src/react-confirm-alert.css';
import { Sharelink } from '../modal/sharelink';
import React from 'react';
export const publisher = (message, link, onConfirm) => {
confirmAlert({
title: message,
message: <Sharelink shareLink={link}/>,
confirmLabel: 'OK',
cancelLabel: '',
onConfirm: onConfirm,
});
document.getElementById("react-confirm-alert").classList.add("publisher");
};
如您所见,“消息”不是消息,而是我开发并希望在警报中看到的名为“Sharelink”的组件。
我检查了从中导入confirmAlert的文件,它说“消息”应该是一个字符串,就像警告说的那样:
_createClass(ReactConfirmAlert, null, [{
key: 'propTypes',
value: {
title: _propTypes2['default'].string,
message: _propTypes2['default'].string,
confirmLabel: _propTypes2['default'].string,
cancelLabel: _propTypes2['default'].string,
onConfirm: _propTypes2['default'].func,
onCancel: _propTypes2['default'].func,
children: _propTypes2['default'].node
},
enumerable: true
}, {
key: 'defaultProps',
value: {
title: false,
message: false,
childrenElement: function childrenElement() {
return null;
},
confirmLabel: false,
cancelLabel: false,
onConfirm: function onConfirm() {
return null;
},
onCancel: function onCancel() {
return null;
}
},
enumerable: true
}]);
一切正常,但我不希望错误消息出现在控制台中,我该如何解决?是否可以仅使控制台中出现的警告静音?
解决方案
推荐阅读
- css - 如何在不遇到标签宽度问题的情况下对齐输入字段
- selenium-webdriver - 量角器 actions.keydown 与 selenium actions.keydown
- javascript - 收到 FCM 通知时如何播放声音
- swift - 删除时的核心数据 EXC_BAD_ACCESS
- amazon-web-services - 如何在不保存到本地 EC2 的情况下将图像从 Amazon EC2 抓取到 S3?
- assembly - 为什么我不能在 NASM 中打印寄存器中的值?
- sparql - 在 SPARQL 查询中按birthYear 和deathYear 标准过滤人员更具执行性
- websocket - Socket.IO 客户端在 3g/4g 连接上无法正常工作
- opencv - OpenCV.js - 遍历轮廓层次结构
- c# - 如何绑定值以形成控件