Validation rules can be specified for component data. san will throw the corresponding error when validation fails. It’s rather useful in collaboration.
Use DataTypes to declare validation rules:
1 | import san, {DataTypes} from 'san'; |
DataTypes provides a series of validators to ensure the data received is valid. In the above example, a DataTypes.string validator is used so that san will throw an error when the value for name is not a String.
For performance considerations, dataTypes only get evaluated in development environment.
Please refer to this link to check out their availabilities in different san releases.
DataTypes
Following is a demo for a variety of DataTypes validators:
1 | import san, {DataTypes} from 'san'; |