Add PropType.identify.
Behind the scenes it will be just a wrapper for
PropTypes.oneOfType([PropTypes.number, PropTypes.string])
Motivation:
We often need a prop that describes some kind of ID. When building a generic module, we often expect our id's to be either a string or a number (thats when we don't know what shape of data we will receive business wise).
Obviously this can be done in "user-land":
Id: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
But this is tedious to write every time and easily missed.
We can abstract it with a custom PropType but we will need to teach other developers on our team (or in contribution guide on github) to use this custom type when dealing with id's.
If we had a built-in, out of the box identify type it would be less tedious and may reduce the need to teach it as its part of the library.
IDs shouldn’t actually ever be numbers, because integers in JS can’t go above 53 bits - IDs should always be strings throughout the entire stack, full stop, or else it will be a very expensive mistake to correct later (twitter had this problem too)
i don’t actually think this is that common a use case, and you can always make a shared idProp in your codebase - you’ll have to teach developers to use something in either case, and you can even write a custom lint rule to force its use for certain property names.
Request:
Add
PropType.identify
. Behind the scenes it will be just a wrapper forPropTypes.oneOfType([PropTypes.number, PropTypes.string])
Motivation:
We often need a prop that describes some kind of
ID
. When building a generic module, we often expect our id's to be either astring
or anumber
(thats when we don't know what shape of data we will receive business wise).Obviously this can be done in "user-land":
Id: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
But this is tedious to write every time and easily missed.
We can abstract it with a custom
PropType
but we will need to teach other developers on our team (or in contribution guide on github) to use this custom type when dealing with id's.If we had a built-in, out of the box
identify
type it would be less tedious and may reduce the need to teach it as its part of the library.