How to solve Warning: React does not recognize the X prop on a DOM element

In my case, I was getting this error when using the IfFirebaseAuthed component from react-firebase.

You must make sure that you return a function inside of this component.

I changed this:

<IfFirebaseAuthed>
  ... My authenticated code here ...
</IfFirebaseAuthed>

To this:

<IfFirebaseAuthed>
 {() => (
    ... My authenticated code here ...
 )}
</IfFirebaseAuthed>

And this issue went away.


This warning appears because you passed a prop on a component that it is not valid.

For example, this

<Component someUnknowprop='random-text' />

will trigger the warning. In order to get rid of the warning you should find out where that warning is coming from. The stack trace should give you a hint.


Presumably, this line must be the culprit:

<FirebaseAuthProvider {...config} firebase={firebase}>

Your config object currently holds fields isSignedIn and providerId, and you must be sending those down to children components, and ultimately to a DOM element. Try removing those fields from the object before you send them down:

const { providerId, isSignedIn, ...authProviderConfig } = config

That way, your object authProviderConfig will not hold the providerId or isSignedIn attributes.

Even better, you can rebuild the configuration object explicitly to avoid any further confusion:

const authProviderConfig = { /* The fields from config FirebaseAuthProvider actually needs */ }

You should also check your FirebaseAuthProvider component to see how it's using those props, and avoid spreading them down to DOM elements.

Related documentation: https://reactjs.org/warnings/unknown-prop.html