Use Svelte 5 Snippets To Reuse Markup Without Creating Components

  Рет қаралды 11,640

Joy of Code

Joy of Code

Күн бұрын

Пікірлер: 116
@kimeiga
@kimeiga 13 күн бұрын
This was crazy. I learned something new every single second.
@SilvestreVivo
@SilvestreVivo Ай бұрын
This is a big step ahead for Svelte
@yeukang
@yeukang 28 күн бұрын
Actually the slots refactor was quite mind-bending to me. So instead of using the let:row, you know create snippets in the parent, and render the snippets in the previously slot component... We still need to rely on IDE hints to know which inner snippets _should_ be defined when consuming the component, and what happens when they're not? Will {@render row(item)} give a type error / crash if not defined? 🤔
@whotao6259
@whotao6259 Ай бұрын
Thanks for sharing 🙌 I haven’t worked too closely with Svelte5, but my general impression of it is that it seems more complex than Svelte4. I think this is really just a reflection of how Svelte wants to solve more complex problems, and trying to make inherently complicated problems simple doesn’t come without compromises. For example, a noticeable friction point with Svelte4 is that you had to be aware of how reactivity could be denoted in multiple ways - stores with dollar signs, reactive labels, and local component variables. It’s easy enough to distinguish and organize in small projects, but it personally made organization and separation of concerns much more complex in large projects. e.g. should I bind to a store or a local variable, should I prop drill bindings or just use a shared store, should I use flux instead of binding altogether, etc? Runes addressed the problem above very elegantly because it effectively answered the questions above with “it can be reactive if it’s $state.” I think many viewed it as a “useState” equivalent without understanding the problems that arose from the originally “simpler” model of reactivity.
@pengain4
@pengain4 Ай бұрын
Love snippets! I needed something like this few times already in the past.
@notnotjake
@notnotjake Ай бұрын
Slot is still used for layouts correct? Where you aren't importing a snippet, just leaving the slot open to children?
@gamecast4432
@gamecast4432 Ай бұрын
Svelte documentation is really great and easy to understand, but man. It's even better when i watch your videos, they're even better than the Svelte docs. From what i learned, slots are easy for easy and simple things, but get really mind bending when things start to get complex. Snippets on the other hand are easy to code in most of the situations i can think of.
@sleepingdog12
@sleepingdog12 13 күн бұрын
Impressive
@lwinklly
@lwinklly Ай бұрын
17:12 sorry WHAT? GENERICS?? I'm in tears, this is amazing, thank you so much Svelte 5
@RisalFajar
@RisalFajar Ай бұрын
It's also available in Svelte 4
@tobychidi
@tobychidi 12 күн бұрын
Generics in Vue too 😊
@miro-hristov
@miro-hristov 13 күн бұрын
Thanks! That was super Easy Peasy Lemon Squeezy 😁
@kmaximoff
@kmaximoff Ай бұрын
I have not watch this video yet, but gonna put thumbs up, just because I know how good your content is. I kind of want to rename it from Joy of Code to Joy of Svelte 😄 Jokes aside, thank you!
@adriablancafort
@adriablancafort Ай бұрын
Amazing.
@wyndmill
@wyndmill Ай бұрын
super useful, thanks
@punishedbarca761
@punishedbarca761 Ай бұрын
No offense to the people in this comment section but I don't think they ship svelte with any level of complexity if they think this is unnecessary. is great but these changes are a huge help for defining edge case render scenarios (that currently look gross and anti-pattern). This just another tool in the toolbox that all of your favourite component/design library creators will love. The best part is that it's opt-in. If you don't want snippets you can just ignore them :D
@TianYuanEX
@TianYuanEX Ай бұрын
Exactly! I don't know what these guys are waffling about, as you said it's literally an opt-in feature. They can simply ignore it if they don't want to use it
@linkinl1
@linkinl1 Ай бұрын
I have used svelte 5 fulltime for the past 6 months, snippets sucks ass, I avoid them like the plauge. The Svelte community has just turned into a massive cope with Svelte 5. Svelte 5's reactivity model is much better than Svelte 4, but the syntax just sucks balls
@NickPoulos
@NickPoulos 13 күн бұрын
I ship lots of Svelte, much more complex than todos and counters -- and Svelte 5 is a step backwards with runes. It is antithetical to why people would pickup Svelte in the first place. The reasons and advantages you got from using Svelte over something like React/Vue have all but disappeared. At this point, why are you not just using React? Bunch of boilerplate, same concepts/mechanisms for props and reactivity, and Svelte's community and ecosystem are much smaller. JSX still sucks but then you can use Vue. All of these things are NOT opt-in, and the "old ways" will become older and older to the point where they are obsolete in Svelte 6.
@punishedbarca761
@punishedbarca761 13 күн бұрын
@@NickPoulos true, i get why you might prefer Svelte 4 if you prefer the Vue method of doing things. My main problem with Svelte 4 is readability and onboarding at scale. I like the route they've taken of clearly defining declarations, which makes code review and test writing 100% easier for me. It's also reduced a lot of my component code which I'm happy about.
@adhecson
@adhecson Ай бұрын
Quite clean!
@TheHermitHacker
@TheHermitHacker Ай бұрын
Thank you!
@JoyofCodeDev
@JoyofCodeDev Ай бұрын
you're welcome 😄
@Ravenpicturez
@Ravenpicturez 10 күн бұрын
Do i have to manually type all the props to not get errors when using snippets? Example: type Props = { route: string; children: Snippet; content: Snippet; }
@JoyofCodeDev
@JoyofCodeDev 9 күн бұрын
you can do `let props = $props()` so TypeScript won't bother you if you don't care about types
@christophebenz
@christophebenz 25 күн бұрын
LOL Patrick Bateman 😂 You are a genius!
@nghiemduonghung9750
@nghiemduonghung9750 Ай бұрын
Is this the solution for layout name slot?
@mikejohneviota9293
@mikejohneviota9293 Ай бұрын
🎉🎉🎉 waiting for svelte 5 migration!!!!
@Donald_Mustard_FN
@Donald_Mustard_FN Ай бұрын
What code editor is this ??
@St0rMsk
@St0rMsk Ай бұрын
Honestly. This is great. Slots are cool, we can say easy, but this is even better. I would like to see projects that people built with svelte who are not excited about svelte 5 / runes, especially the - you didnt have to learn svelte, now you do crowd. Wtf... You had to learn svelte when you eent beyond simple counter example. I do aswell have some "isues" with new APIs, but remember, you can still use the old stuff with svelte 5
@nathnaelgetachew7379
@nathnaelgetachew7379 Ай бұрын
This just doesn't look like svelte....
@AlanDanielx
@AlanDanielx Ай бұрын
@@nathnaelgetachew7379 noob developers always say that. Its very common
@leigh321
@leigh321 Ай бұрын
Lower case boom 🥹
@htichpirate
@htichpirate 9 күн бұрын
why have a footer tag in snippet and around the render also one? That's result a footer tag in footer tag..
@JoyofCodeDev
@JoyofCodeDev 9 күн бұрын
simple mistake
@htichpirate
@htichpirate 8 күн бұрын
@@JoyofCodeDev ah, ok, thank you for clarification :)
@davidjacobs7966
@davidjacobs7966 Ай бұрын
I don't understand some devs' arguments against a single component per file. That's supposed to be the essence of component-oriented programming. 😅
@JoyofCodeDev
@JoyofCodeDev Ай бұрын
the real power is providing your own render function
@jamesmoynihan948
@jamesmoynihan948 Ай бұрын
@davidjacobs7966 I love SFCs, but snippets still have a use when you repeat a pattern within a component. Does it really need to be a whole new component just to avoid repeating myself in the markup? I'd argue there's a decent amount of code repetition when the code gets over-fractured as well.
@shapelessed
@shapelessed Ай бұрын
If you were to compare React to Linux, Svelte woud be MacOS - Gets out of your way so you can do your job instead of fixing some niche and random issues. Now it's becoming Windows 11...
@JoyofCodeDev
@JoyofCodeDev Ай бұрын
idk
@sadunozer2241
@sadunozer2241 Ай бұрын
I’m an unreal engine programmer. I build the engine from source, with 120GB debug symbols and it’s all just there. it has a DX Ilthat I love and cherish… and Rich Harris is probably the only one in the web domain who, I think, has a similar engine/plugins/game-project mindset which is simply fun and productive to work with. Svelte is Debian. It’s solid, it’s got everything you need, it’s lean as fuck
@shapelessed
@shapelessed Ай бұрын
@@sadunozer2241 It was.
@pixiedev
@pixiedev Ай бұрын
In svelte 5 just the slot-children is different else everything is same as vue 😅
@JoyofCodeDev
@JoyofCodeDev Ай бұрын
I find this amusing because the future of Vue (Vapor) looks more like Svelte
@m_raez
@m_raez Ай бұрын
@@JoyofCodeDev if something works well, use it or copy it for your integration. Developers copy from each other and library/framework authors do the same. If it solves problems and provides good abstraction or ergonomics, why not?
@rafalpotasz
@rafalpotasz Ай бұрын
​@@m_raez I don't think JOC is saying anything that would disagree with you tbh. I agree though. Copy the best things, learn their patterns, improve your own thinking for free essentially?
@JoyofCodeDev
@JoyofCodeDev Ай бұрын
everyone wins
@NickPoulos
@NickPoulos 13 күн бұрын
You didn't know? React/Vue/Svelte are all just merging into one big ball of the same features with slightly different syntax now!
@icemelt7ful
@icemelt7ful 24 күн бұрын
ezy pezy lemon squezy
@NatoBoram
@NatoBoram Ай бұрын
Hm... I'm not really convinced. Making new components is just good project hygiene tbh. I'll have to test it to see where I have a use case for that. That said, the experience looks great if there's a good use case for them Oh, generic! Now, I see. That's game changing!
@ChadcholMeesaeng
@ChadcholMeesaeng 20 күн бұрын
let's see paul allen's snippet
@m_raez
@m_raez Ай бұрын
createRawSnippets looks rather similar to Vue's defineComponent to create Components in JS/TS without SFC-files.
@JoyofCodeDev
@JoyofCodeDev Ай бұрын
one step closer to having a custom renderer 🔥
@lucasmiguel2633
@lucasmiguel2633 Ай бұрын
IMHO Svelte is losing the “it just feels natural” feeling that you got, for example, when using I was hoping this video to change my mind but it just made me more confident of my stance in favor of Svelte 4. Svelte 5 is Vue. Might make more sense, but you need to put more boilerplate and concepts that just make it less fun to work with
@JoyofCodeDev
@JoyofCodeDev Ай бұрын
curious how is `` more natural than `{@render children()}`? not only do you live in the age of autocomplete but the upside is more than worth a couple of extra characters - the more people use Svelte and provide feedback makes it easier to know what to focus on and improve
@stathiskapnidis9389
@stathiskapnidis9389 Ай бұрын
​@@JoyofCodeDev is simpler because it just looks like an html element. Like put this here and then something renders. {@render children()} makes it more ambiguous because what now you have to understand what @render does, when it does it, and what children() does, when it gets called, if it updates dynamically, etc. Before it was as if you were placing something there like a or a . Easy to understand. Now it does something. But you don't neceserily know what. You can learn, but before you didn't need to learn. It was intuitive
@JoyofCodeDev
@JoyofCodeDev Ай бұрын
I see more beginners confused by `` and treating it like a black hole avoiding things like `let` because it's mind-bending but `{@render children()}` is more explicit and I would argue more intuitive if you understand functions
@lucasmiguel2633
@lucasmiguel2633 Ай бұрын
@@JoyofCodeDev you have a point there. However I wouldn’t know how to do binding using render functions
@亞米歐弟沒有
@亞米歐弟沒有 Ай бұрын
I think the changes are inspired by React. In Svelte 5, using {@render} and {#snippet}, you can pass them as props or treat them just like variables in JavaScript easily. But yeah, they should've kept the native for those people who don't need it.
@mikemcculley
@mikemcculley Ай бұрын
"That's 'bone.' Unfortunately, it's not a named color in CSS."
@DanteMishima
@DanteMishima Ай бұрын
Yeah... I won't be using svelte 5.... It's too weird for me.
@mynameisnotshane6501
@mynameisnotshane6501 Ай бұрын
Coming from react js world i feel like i came out of a cave era
@icemelt7ful
@icemelt7ful 24 күн бұрын
so we're 50% there on the way to make react
@nabeelalihashmi
@nabeelalihashmi Ай бұрын
I might be wrong, but I feel like Svelte is moving away from what it made Svelte 😥
@JoyofCodeDev
@JoyofCodeDev Ай бұрын
you're wrong 😄
@kollpotato
@kollpotato Ай бұрын
no one holds you back from using the old versions of svelte, if they work for you then use them without hesitations
@jamesmoynihan948
@jamesmoynihan948 Ай бұрын
What specifically do you think is worse or missing? For me, runes and snippets solve a lot of pain points that arise when building a larger app.
@nabeelalihashmi
@nabeelalihashmi Ай бұрын
@@JoyofCodeDev 😎 😎 you're {#probably right}🤣
@nabeelalihashmi
@nabeelalihashmi Ай бұрын
@@jamesmoynihan948 Moving away doesn't mean worsening the matters. That's a good thing if runes are solving inconsistency issues. But, my theory is, many people, chose Svelte due to simplicity. And let x = 10 is simplicity, and export let y in component is also a simplicity. a question, when talking about larger applications, what number of loc defines "larger application"?
@davidjacobs7966
@davidjacobs7966 Ай бұрын
when is ready Svelte 5?
@JoyofCodeDev
@JoyofCodeDev Ай бұрын
I predict the release at next Svelte Summit 🔮
@AlanDanielx
@AlanDanielx Ай бұрын
@@JoyofCodeDev Mission Failed
@AlanDanielx
@AlanDanielx Ай бұрын
don't wait until svelte 5, try out the pre-release, it's not going to change a lot
@nsoneu
@nsoneu 13 күн бұрын
5 lemon squeeze so far... my ears are bleeding 😂.. great content though.
@JoyofCodeDev
@JoyofCodeDev 13 күн бұрын
🍋
@nsoneu
@nsoneu 13 күн бұрын
@@JoyofCodeDev thank you for your video i also meant to write 🙌
@GeraldScholz
@GeraldScholz Ай бұрын
Lol snippets are awful 😂 sorry
@Holobrine
@Holobrine Ай бұрын
TIL Svelte 5 supports generics, very cool
@JoyofCodeDev
@JoyofCodeDev Ай бұрын
it also has native TypeScript support
@imho7992
@imho7992 Ай бұрын
Yeah this was a surprise. Does this mean i don’t need to define a type prop for my components anymore? 🤯
@roastgg
@roastgg 4 күн бұрын
Terrible, horrible, so bad. Props and slots are perfect. Overtly verbose snippet syntax is ridiculous.
@roiborromeo7921
@roiborromeo7921 Ай бұрын
This isn't what makes Svelte promising.
@Floubadour
@Floubadour 10 күн бұрын
Easy peasy lemon squeezy. Please, do not repeat it so many times!
@JoyofCodeDev
@JoyofCodeDev 9 күн бұрын
that's going to be easy peasy lemon squeezy
@cromrin
@cromrin Ай бұрын
I personally dont like snippets I like more the lets put it into its separate component type of stuff. If I use component on multiple places lets put it into /components if I use It only in specific page I put it next to +page.svelte inside _components. The code is so much clearer to read the less lines of code it has. I am that guy who does like if all code lines of a file fits into his view 0 +/-125 lines of code.
@realderek
@realderek Ай бұрын
This concept seems "alright" to me. I think the problem is that developers loved the allure of a straight-forward framework like Svelte. The problem is, for more complex use cases it wasn't as simple. Now that it's becoming more flexible to accommodate the complex use cases (such as UI libraries), it's losing the appeal of being a "straight-forward" framework.
@JoyofCodeDev
@JoyofCodeDev Ай бұрын
balanced take
@stathiskapnidis9389
@stathiskapnidis9389 Ай бұрын
svelte 5 continues to disapoint me
@ok-alarm
@ok-alarm Ай бұрын
heyy, why?
@danko95bgd
@danko95bgd Ай бұрын
@@ok-alarm because snippets suck
@stathiskapnidis9389
@stathiskapnidis9389 Ай бұрын
​@@ok-alarm slot was so much easier. Now I have to do children() and other stuff like that. The beuty of svelte was it's simplicity.
@Dhalucario
@Dhalucario Ай бұрын
I think using children() is nicer because you have an unified way to get the child elements in your component in js and html
@JoyofCodeDev
@JoyofCodeDev Ай бұрын
you can mix them together if you want
@HIChoi-q8e
@HIChoi-q8e 13 күн бұрын
Ugly. If you want to use nested component outside of the component, pull out the component is clear way to reuse.
Recording Videos Using JavaScript And Browser APIs
26:59
Joy of Code
Рет қаралды 3,5 М.
Svelte 5's Secret Weapon: Classes + Context
18:14
Huntabyte
Рет қаралды 25 М.
Perfect Pitch Challenge? Easy! 🎤😎| Free Fire Official
00:13
Garena Free Fire Global
Рет қаралды 66 МЛН
Motorbike Smashes Into Porsche! 😱
00:15
Caters Clips
Рет қаралды 22 МЛН
Yay, My Dad Is a Vending Machine! 🛍️😆 #funny #prank #comedy
00:17
Car Bubble vs Lamborghini
00:33
Stokes Twins
Рет қаралды 35 МЛН
Svelte 5 Is Like React, But Better
19:33
Theo - t3․gg
Рет қаралды 73 М.
Understanding Effects In Svelte 5 And When To Use Them
27:31
Joy of Code
Рет қаралды 8 М.
Using Svelte Stores With Svelte 5 Runes To Create Runed Stores
18:59
Svelte 5 Snippets: Revolutionizing UI Composition | Snippets Vs Slots
12:09
Fullstack Ninja Academy
Рет қаралды 1,1 М.
The Svelte 5 Migration Guide
50:41
Joy of Code
Рет қаралды 4,7 М.
useSyncExternalStore и примеры практического использования
17:15
I Tried Every Svelte UI Library
20:57
Joy of Code
Рет қаралды 51 М.
A New Drag And Drop Library For EVERY Framework
16:02
Theo - t3․gg
Рет қаралды 165 М.
Svelte 5 Preview | Runes
12:40
ThePrimeTime
Рет қаралды 79 М.
Let's Make A Todo App Using Svelte 5 Runes
26:55
Joy of Code
Рет қаралды 28 М.
Perfect Pitch Challenge? Easy! 🎤😎| Free Fire Official
00:13
Garena Free Fire Global
Рет қаралды 66 МЛН