Search code examples
reactjscomponentsprop

Unknown prop on Component that is capitalized


I'm getting the following error:

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

I get it that this happens when transferring props which are not standard on a dom element, however here I'm trying to use my own component. Here is the render method:

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

    let Tag = "NotificatonType." + type;

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

Solution

  • The problem is caused by this line:

    let Tag = "NotificatonType." + type;

    You need to pass a React custom element, not a string with the class/function name. This way to React it looks like a DIV or similar.

    You could probably do this instead:

    let Tag = NotificationType[type] but without seeing you NotificationType code is hard to figure.