Comments (6)
This can work too:
{#if snippetHeader}
{@render snippetHeader()}
{:else}
myDefaultContent
{/if}
No need for a second snippet name when done like this
from svelte.
snippets can take params and the aim is to remove the markup from the logic, so this is not a good alternative
from svelte.
snippets can take params and the aim is to remove the markup from the logic, so this is not a good alternative
Wdym by "snippets can take params"? snippetHeader
could also take a param in this case.
from svelte.
right from the docs
{#snippet figure({ src, caption, width, height })}
<figure>
<img alt={caption} {src} {width} {height} />
<figcaption>{caption}</figcaption>
</figure>
{/snippet}
also you gonna lose the possiblity to pass the 'defaultSnippet' to another Component
from svelte.
If you actually need a default snippet to further pass around, you can define it as necessary.
This does not seem all that common of a requirement.
If you have default content in an else
branch, you can directly use the variables in scope, the only thing the snippet adds is destructuring, which can be done with @const
.
{#if snippetHeader}
{@render snippetHeader(data)}
{:else}
{@const { a, b, c } = data}
...
{/if}
Do not see an issue with arguments here.
from svelte.
All these use cases can be solved with if/else blocks or fallback snippets being applied. We're not going to introduce different syntax for this, therefore closing.
from svelte.
Related Issues (20)
- Svelte 5, I'm using `$state.snapshot` but a nested array is still a `Proxy`
- Calculated CSS unit HOT 2
- `read_pattern` fails if brackets are in strings etc HOT 2
- Expose `set_raf` in Svelte 5 HOT 1
- Svelte 5 Next 164: FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory HOT 1
- [email protected] breaks snippets with arguments typed as an object literal HOT 11
- setTimeout does not rerender component when using lifecycle functions HOT 1
- [ Svelte 5 + SortableJS ] Cannot read properties of null (reading 'nextSibling') since 5.0.0-next.162 HOT 1
- Whitespaces are not preserved in non-`pre` tags, even with `white-space; pre;` on. HOT 2
- $effect fails in some cases HOT 3
- Svelte 5: Missing warning for non-state use in `$effect`? HOT 5
- Svelte 5: compiler silently fail when snippet is not properly parsed
- Allow aria-valuetext for elements with `role="slider"`
- 🐞 FATAL ERROR (next.164): Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory HOT 2
- Svelte 5: dispatched "native named" events not reaching handler HOT 16
- What does 'Object.defineProperty called on non-object' mean in $effect? HOT 2
- Svelte 5: Discriminating Unions with Type Narrowing doesn't work HOT 3
- Svelte 5: Reintroduce `frame`/`pos`/`toString()` in compiler warnings
- Svelte 5: Placeholder in select not displayed HOT 6
- Passing stateful arrays down with getters do not work on libraries HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svelte.