首页 > 解决方案 > 警告:“对象”类型的道具类型失败,应为字符串

问题描述

我正在使用 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
  }]);

一切正常,但我不希望错误消息出现在控制台中,我该如何解决?是否可以仅使控制台中出现的警告静音?

标签: reactjsreduxcomponents

解决方案


推荐阅读