In the last step, you added a dateStr property that could be set from an attribute, but your component's date property is still being set with JavaScript. Requiring JavaScript to set a property is not ideal for users of a <date-display> because setting properties this way is not as readable or easy as setting attributes.

In this step, you'll add code to synchronize the date property with the dateStr property whenever dateStr changes.

Accept date-str as an attribute

Permalink to "Accept date-str as an attribute"

index.html

Permalink to "index.html"

Now you may notice that the date displayed is not the same as the one you passed in. This is because the date property is being rendered. date needs to be synchronized with dateStr whenever dateStr changes.

Update date when dateStr changes

Permalink to "Update date when dateStr changes"

The willUpdate method is a good place to reconcile two different reactive properties.

For more information, see Lit lifecycle!

date-display.

Permalink to "date-display."

Now the correct date should be displayed when the date-str attribute changes!

Adding the dateStr property and imperative code in willUpdate() works, but it's not ideal. We don't recommend using this pattern in your own code. Instead, you should use a custom attribute converter, as shown the following steps.