Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sacrosanctic opened this issue Oct 29, 2024 · 2 comments · May be fixed by #15172
Open

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

sacrosanctic opened this issue Oct 29, 2024 · 2 comments · May be fixed by #15172

Comments

@sacrosanctic
Copy link
Contributor

sacrosanctic commented Oct 29, 2024

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

@brunnerh
Copy link
Member

As far as I can tell all of that is there.

Within the template, snippets are values just like any other. As such, they can be passed to components as props

As an authoring convenience, snippets declared directly inside a component implicitly become props on the component

Any content inside the component tags that is not a snippet declaration implicitly becomes part of the children snippet

@sacrosanctic
Copy link
Contributor Author

sacrosanctic commented Oct 29, 2024

Then I'm specifically asking about a code block example.

Secondary goal, I would like the various options to be more obvious, siting prior art like {#if...}

image

or export from mdn https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export

image

@sacrosanctic sacrosanctic linked a pull request Feb 1, 2025 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants