【问题标题】:Unknown prop on Component that is capitalized大写的组件上的未知道具
【发布时间】:2017-10-30 13:59:42
【问题描述】:

我收到以下错误:

warning.js:35 Warning: Unknown prop `notification` on <NotificatonType.InvitedToEventNotification> tag. Remove this prop from the element.

我知道在传输 dom 元素上不标准的道具时会发生这种情况,但是在这里我尝试使用我自己的组件。这是渲染方法:

render() {
    const type = this.props.notification.type;

    let Tag = "NotificatonType." + type;

    return <Tag {...this.props}/>
}

【问题讨论】:

  • 我相信 React 16 删除了这个警告。

标签: reactjs components prop


【解决方案1】:

问题是由这一行引起的:

let Tag = "NotificatonType." + type;

您需要传递一个 React 自定义元素,而不是带有类/函数名称的字符串。这种 React 方式看起来像 DIV 或类似的。

你可以这样做:

let Tag = NotificationType[type] 但没有看到你,NotificationType 代码很难理解。

【讨论】:

    猜你喜欢
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    • 2017-12-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多