Skip to content

[docs] Snippet docs doesn't mention direct/explicit method #14020

@sacrosanctic

Description

@sacrosanctic

TLDR

https://svelte.dev/docs/svelte/snippet#Passing-snippets-to-components

Would like to add a section to explain the direct/explicit method

let { foo } = $props();

{@render foo()}

Explanation

As far as i can tell there are 3 ways, and the second one direct/explicit doesn't seem to be mentioned at all.

Currently is unclear what the various snippet options are in comparison to its counterpart {#if...} and {#each...}

  • direct/implcicit
// Parent.svelte
<Child>
  <h1>Title!</h1>
</Child>

// Child.svelte
<script>
  let { children } = $props();
</script>

{@render children()}
  • direct/explicit
// Parent.svelte
<Child>
  {#snippet foo()}
    <h1>Title!</h1>
  {/snippet}
</Child>

// Child.svelte
<script>
  let { foo } = $props();
</script>

{@render foo()}
  • indirect/explicit
// Parent.svelte
{#snippet foo()}
  <h1>Title!</h1>
{/snippet}

<Child {foo} />

// Child.svelte
<script>
  let { foo } = $props();
</script>

{@render foo()}

Reference

https://discord.com/channels/457912077277855764/1300850418728960000

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy