New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Prop default value & validation & required #236
Comments
All of this is already within stencil :) default values@Component({ tag: 'x-greet' })
class Hello {
@Prop() who = 'World'
render(){ return <div>Hello {this.who} !</div>
} <x-greet></x-greet> will render -> required / validations@Component({ tag: 'x-greet' })
class Hello {
@Prop() who: string
@PropWillChange('who')
validateWho(newValue: string) {
const isBlank = typeof newValue == null
const atLeast2chars = typeof newValue === 'string' && newValue.length >= 2
if (isBlank){ throw new Error('who: required') }
if ( !atLeast2chars ) { throw new Error('who: atLeast2chars') }
}
} also I would definitely enable those validations only for Development env |
Right, thanks @Hotell! |
Reminds me to add this to the docs. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prop should have the same propeties that props in vue has
type (already have)
required
default (should be callback)
validation
The text was updated successfully, but these errors were encountered: