PropTypes of React allow to create custom validators. For example, for the value:
[{propOne: 'string', propTwo: 2}, {propOne: 1, propTwo: 'value'}];
It is possible to validate whether:
- this value is an array
- this value consists of objects
- objects are not instances of arrays
- this value's length is 2
- each object of this value has exactly 2 props
- the value of the first prop of the first object is a string
- the key of the first prop of the first object is propOne
- a.s.o for each value
Should I write this kind of prop validation using PropTypes or it is better to stick to shallow validation with PropTypes and dedicate most of the job to Unit Testing?
Aucun commentaire:
Enregistrer un commentaire