facebook / prop-types

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

[new] add `PropTypes.literal` #396

Closed wojtekmaj closed 1 year ago

wojtekmaj commented 1 year ago

Currently, to check if value is exactly something, we need to do it in a way that feels a bit hacky:

PropTypes.oneOf([value])

With this proposal, one could use:

PropTypes.literal(value)

to achieve the same thing.

ljharb commented 1 year ago

I'm not sure the benefit here is worth the complexity of adding an entirely new propType.