Svelte Basics
Svelte Basics
Introduction
- Use
{}to embed JS expressions
| |
- Use
<style>to add styles
| |
- Import and use components
| |
- Turn strings into HTML code
| |
Reactivity
- Creation and modification of “State”
$… are called Runes
| |
- “Deep State”
| |
- “Derived State”
| |
- State “Snapshot”
| |
- “Effects”
| |
- Using “State” outside of Svelte files
| |
Component “Props”
- Declaring “Props”
| |
- Default values for props
| |
- Passing props
| |
“Logic” in HTML
- Branching (
#if,:else if,:else,/if)
| |
- Iteration (
#each as)
| |
- Iteration with “Keys”
| |
- Async
| |
Events
- Listening to events
| |
- Using “Capture” instead of “Bubbling” for event handling
| |
- Components passing Event Handlers outward
| |
(Two-way) Binding
- Syntax
| |
bind:group: Radio/Checkbox group
| |
<select multiple>
| |
Classes and Styles
- clsx support
| |
style:
| |
- Specifying child component styles in a parent component
| |
Actions
| |
| |
Transitions
- Syntax
| |
- Custom CSS transitions
| |
- Custom JS transitions
| |
- Transition events
| |
- Global transitions
By default, transitions only trigger when the immediate parent block’s content is added or removed.
| |
- Key block
Force a transition to trigger by completely destroying and recreating the content.
| |
Last updated on