Using multiple components
Svelte Component Cheat-Sheet
1. Create a Child Component
File: src/components/ChildComponent.svelte
2. Use the Child Component in Main App Component
File: src/App.svelte
3. Display Result in Browser
URL: localhost
Hello, Svelte!
Key Points
Exporting Props in Child Component:
const { name } = $props();
: Svelte-specific syntax to allow prop passing.
Using Child Component in Parent:
import
: Standard JavaScript ES6 syntax.<ChildComponent name="Svelte" />
: Svelte-specific syntax for including a component and passing props.
Ensure that the file path in the import statement is correct. Incorrect paths will result in errors.
Last updated