Vue Props Validations – Best Practices
Hey folks!
I wrote a tutorial about vue props validation and best-practices
Some of the topics covered:
- Basic Validations
- Camel-Case => Kebab-Case
- Native Constructs Validation
- Function Constructor Validation
- Custom Validators Functions
- Default Prop Values
- Best Practices & Guidelines
Some of the best-practises I could think of:
* Always validate your props.
* Always have a default value for non-required props.
* Don't add a default value for required props.
* Never mutate the prop, it may affect the parent's state in case of mutating objects & arrays.
* Validator & default functions should be stateless since they run before the component is created.
* Avoid declaring more than one type to a prop.
Any feedback is appreciated, cheers!