Send me an email directly at [email protected] or use the form below to send me a message.
Having only recently started using SvelteKit I was impressed with how easy it was to get started and surprised by how much I enjoyed using it. Here are six of the features that I found particularly useful whilst I was learning the framework.
When passing a property to an element or component you can use the shorthand syntax if the variable name is the same as the property name. This makes the code cleaner and easier to read, and saves you having to specify the property name.
1 | |
2 | |
3 | |
4 | |
5 | |
Svelte provides the slot
element which allows you to pass child content to a component. If you want to have multiple
slots on a component you can give each slot a name and then reference that name when passing content to the slot, making
it easy to control how the child content is rendered.
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
Getting a reference to an element can be frustrating in some frameworks, but Svelte makes it easy with the bind:this
directive. Once you have the element reference you can access its exported properties and functions directly.
1 | |
2 | |
3 | |
4 | |
5 | |
Svelte allows you to emit custom events that can be subscribed to using the on:
directive, making it easy to trigger
an action in or pass data out of a parent component.
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
For more information see the docs.
Using the export
keyword you can export functions from a component that can be invoked from outside the component,
making it easy to trigger an action on or pass data into a child component.
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
When using #await
you can animate the new elements as they are added to the DOM using Svelte's in-built transitions.
The transitions are applied to the element using the in:
directive and can be easily customised.
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
For more information see the docs.
SvelteKit is a powerful and fully featured framework with comprehensive documentation and a very active community. This list only scratches the surface of all the great features built in.
I've personally fallen in love with it and would highly recommend you give it a try on your next project.