Skip to content

What is the correct way to validate properties ? #3715

Answered by augustjk
Mushr0000m asked this question in Q&A
Discussion options

You must be logged in to vote

Custom converters only apply if users are providing the properties as attributes as that's when a converter would be called. If users are providing them as properties, you have a couple of options:

  1. Use willUpdate() lifecycle to read the value and make any necessary changes before update/rendering. https://lit.dev/docs/components/lifecycle/#willupdate

  2. Create custom property accessors (getters and setters) and do the validation on the setter. https://lit.dev/docs/components/properties/#accessors-custom

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by Mushr0000m
Comment options

You must be logged in to vote
1 reply
@augustjk
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants