Lifecycles in Svelte
Svelte is a frontend framework. You can use Svelte to build websites and web applications. A Svelte application is made up of components. You write a Svelte component within a file with .svelte
extension. Each .svelte
file is one Svelte component.
When you create and use a Svelte component, the component goes through various stages of the component lifecycle. Svelte provides lifecycle functions, allowing you to hook into the different stages of the component.
In this chapter, we will start by talking about the various lifecycles and the lifecycle functions in Svelte. With a clear idea of lifecycles in mind, you will then learn the basic rule of using the lifecycle functions. This is essential, as you will see that this understanding will allow us to use the lifecycle functions in a lot of creative ways.
This chapter contains sections on the following topics:
- What are Svelte lifecycle functions?
- The rule of calling lifecycle functions
- How to reuse and compose lifecycle functions