facebook / prop-types

Runtime type checking for React props and similar objects
MIT License
4.48k stars 356 forks source link

Proptype for Context.Provider #223

Closed eedrah closed 5 years ago

eedrah commented 6 years ago

Is there a proptype for Context.Provider? If I use element I get the following error message:

Warning: Failed prop type: Invalid prop `ContextProvider` of type `object` supplied to `myComponent`, expected a single ReactElement.

and if I use node I get:

Warning: Failed prop type: Invalid prop `ContextProvider` supplied to `myComponent`, expected a ReactNode.
eedrah commented 6 years ago

I just got the same thing for Consumer also. Currently I'm using object, but that seems like a shame, as that is going to match a lot more than wanted.

ljharb commented 6 years ago

Seems related to #211.

eedrah commented 6 years ago

Agreed it will be fixed with #211, so closed in favor of that pull request

henrik commented 2 years ago

Because it took me a little while to figure out – the thing #211 ended up adding specifically is PropTypes.elementType, which seems to work fine for a provider.