* New FAQ, new renderer * Push blog stuff * Fix blog posts * Add tutorial to be rendered * Update documentation/content/blog/2023-03-09-zero-config-type-safety.md Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> * Update documentation/content/blog/2023-03-09-zero-config-type-safety.md Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> * Revamp a lot of renderer, make it (soft) compatible with sveltekit * Remove markdown types * Clean up faq +page * Document stuff * Make the options more explicity * chore(site-2): Restructure docs pt 2 (#8604) * Push * Update readme * Push * inor accessibility fix * minr stuff * Add prepare * Run prettier * Remove test script * pnpm update * Update sites/svelte.dev/src/routes/examples/[slug]/+page.svelte Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> * Update sites/svelte.dev/package.json Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> --------- Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> --------- Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
1.0 KiB
title |
---|
Nested components |
It would be impractical to put your entire app in a single component. Instead, we can import components from other files and then use them as though we were including elements.
We now present you 2 files in the editor on the right (upper bar) to click on, App.svelte
and Nested.svelte
.
Each .svelte
file holds a component that is a reusable self-contained block of code that encapsulates HTML, CSS, and JavaScript that belong together.
Let's add a <script>
tag to App.svelte
that imports the file (our component) Nested.svelte
into our app...
<script>
import Nested from './Nested.svelte';
</script>
...then use component Nested
in the app markup:
<p>This is a paragraph.</p>
<Nested />
Notice that even though Nested.svelte
has a <p>
element, the styles from App.svelte
don't leak in.
Also notice that the component name Nested
is capitalised. This convention has been adopted to allow us to differentiate between user-defined components and regular HTML tags.