Lifecycle of the Svelte Component
Understanding lifecycle of component is important to implement.
This post is one of Svelte Tutorial series.
The svelte has some lifecycle functions.
onMount: runs after the component is first rendered to the DOM.
onDestroy: runs when the component is destroyed.
beforeUpdate: runs before the DOM has been updated.
afterUpdate: runs after the DOM has been updated(It's counterpart of the
tick: unlike other functions(I'll describe at the last part of this post).
It’s interesting that onDestroy function of the child component runs after parent component’s.
tick is special function. It can be called any time unlike other lifecycle functions except when the component first initializes.
It returns a promise that resolves as soon as any pending state changes have been applied to the DOM.
We are also always interested in helping to promote quality content. If you have an article that you would like to submit to any of our publications, send us an email at email@example.com with your Medium username and we will get you added as a writer. Also let us know which publication/s you want to be added to.