Huntabyte
Huntabyte
  • 115
  • 1 634 814
Svelte 5's Secret Weapon: Classes + Context
In this video, we'll start with some basic markup and bring it to life using Svelte 5 Runes and other new Svelte 5 APIs. Specifically, we'll be creating a "Toaster" component along with its state that will enable us to push toast notifications from anywhere in our app.
If you enjoy this type of content, please let me know, and I'll gladly create more!
Global State Video: czcams.com/video/EyDV5XLfagg/video.html
Starting Code: github.com/huntabyte/svelte-5-context-classes/tree/starting-code
Final Code: github.com/huntabyte/svelte-5-context-classes
📁 GitHub: hj.run/github
🌐 Personal Site: hj.run
🚀 Modern SaaS Course: hbyt.us/modern-saas
💬 Discord: hj.run/discord
🐦 X/Twitter: hj.run/x
🖥️ Setup Stuff: hj.run/uses
📃 Topics Covered:
- Svelte 5 Runes
- Svelte 5 $state
- Svelte 5 $effect
- Svelte 5 $derived
- Svelte 5 reactivity
- Svelte 5 classes
- Svelte 5 context
- Svelte context API
- Svelte global state
- Svelte class state
- Svelte reactive classes
zhlédnutí: 14 812

Video

Svelte Has Been Hiding Something...
zhlédnutí 7KPřed měsícem
A couple months ago a friend of mine told me about Svelte's "secret" @component comment blocks. These blocks let you add JSDoc-like comments to your Svelte components so consumers can read them by simply hovering over the component. There is an open PR to add this to the documentation, so it seems they don't plan on hiding it forever 😉 🌐 Personal Site: hj.run 🚀 Modern SaaS Course: hbyt.us/moder...
DevTools, but for Mobile Browsers
zhlédnutí 13KPřed měsícem
Debugging mobile browsers can be a royal pain in the rear, especially without access to DevTools. Fortunately, an amazing open-source project called Eruda enables you to add DevTools to any platform. This is incredibly useful for things like checking console logs on mobile, inspecting elements, etc.! Eruda: - Github: github.com/liriliri/eruda - Website: eruda.liriliri.io/ 🌐 Personal Site: hj.ru...
Practical Svelte 5 - Shopping Cart
zhlédnutí 13KPřed měsícem
In this video, we'll start with some basic markup and bring it to live using Svelte 5 Runes and other new Svelte 5 APIs. If you enjoy this type of content, be sure to let me know and I'll gladly make more! Starting Code: github.com/huntabyte/svelte-mart/tree/starter-code FInal Code: github.com/huntabyte/svelte-mart/ 🌐 Personal Site: hj.run 🚀 Modern SaaS Course: hbyt.us/modern-saas 💬 Discord: hb...
Svelte UI Libraries Have Leveled Up
zhlédnutí 57KPřed 6 měsíci
In this video, we'll go over Melt UI, Bits UI, and shadcn-svelte. We'll talk about what makes each unique, and which one you should choose based on your preferences! Melt UI github.com/melt-ui/melt-ui melt-ui.com Bits UI github.com/huntabyte/bits-ui bits-ui.com shadcn-svelte github.com/huntabyte/shadcn-svelte shadcn-svelte.com 🚀 Modern SaaS Course: hbyt.us/modern-saas 💬 Discord: hbyt.us/discord...
Global Stores Are Dangerous
zhlédnutí 15KPřed 7 měsíci
Global Stores Are Dangerous
I already love SvelteKit v2
zhlédnutí 37KPřed 7 měsíci
I already love SvelteKit v2
Don't Sleep on Svelte 5
zhlédnutí 43KPřed 10 měsíci
Don't Sleep on Svelte 5
Level Up Your Svelte Stores
zhlédnutí 19KPřed 10 měsíci
Level Up Your Svelte Stores
SvelteKit Rate Limiting with Upstash Redis
zhlédnutí 8KPřed 11 měsíci
SvelteKit Rate Limiting with Upstash Redis
A Trick for Cleaner Svelte Components
zhlédnutí 50KPřed rokem
A Trick for Cleaner Svelte Components
The Anti Component Library
zhlédnutí 47KPřed rokem
The Anti Component Library
Pass Messages between Pages in SvelteKit
zhlédnutí 14KPřed rokem
Pass Messages between Pages in SvelteKit
Best UI Library for Svelte
zhlédnutí 106KPřed rokem
Best UI Library for Svelte
Pagination with SvelteKit
zhlédnutí 19KPřed rokem
Pagination with SvelteKit
Better Protected Route Redirects
zhlédnutí 26KPřed rokem
Better Protected Route Redirects
Forms Will Never Be the Same
zhlédnutí 53KPřed rokem
Forms Will Never Be the Same
ChatGPT API - Build A Chatbot App
zhlédnutí 152KPřed rokem
ChatGPT API - Build A Chatbot App
Let's Build a Custom GPT-3 AI Application
zhlédnutí 18KPřed rokem
Let's Build a Custom GPT-3 AI Application
New SvelteKit Feature - Defer
zhlédnutí 20KPřed rokem
New SvelteKit Feature - Defer
Error Handling in 9 minutes (feat. Sentry)
zhlédnutí 15KPřed rokem
Error Handling in 9 minutes (feat. Sentry)
New SvelteKit Feature - Snapshots
zhlédnutí 14KPřed rokem
New SvelteKit Feature - Snapshots
SvelteKit Authentication with Lucia & Prisma
zhlédnutí 49KPřed rokem
SvelteKit Authentication with Lucia & Prisma
Speed Up Your Apps with Cache Control
zhlédnutí 19KPřed rokem
Speed Up Your Apps with Cache Control
SvelteKit & Prisma Full-Stack CRUD Application
zhlédnutí 45KPřed rokem
SvelteKit & Prisma Full-Stack CRUD Application
Why Your Load Functions are Slow
zhlédnutí 20KPřed rokem
Why Your Load Functions are Slow
Dark Mode Theme Switcher in Svelte
zhlédnutí 14KPřed rokem
Dark Mode Theme Switcher in Svelte
Build a Reactive Search Filter with Svelte
zhlédnutí 25KPřed rokem
Build a Reactive Search Filter with Svelte
10X Your SvelteKit Developer Experience in VSCode
zhlédnutí 37KPřed rokem
10X Your SvelteKit Developer Experience in VSCode
Supabase OAuth with SvelteKit (Discord, Google, GitHub)
zhlédnutí 17KPřed rokem
Supabase OAuth with SvelteKit (Discord, Google, GitHub)

Komentáře

  • @charlesokorobo508
    @charlesokorobo508 Před 18 hodinami

    Can you do a Tutorial where we will create a Facebook clone-- using Svelte, SvelteKit, Postgres Database, Drizzle ORM and Lucia Authentication. This tutorial is a big Application (I know), but then, it will be a series like this -- czcams.com/video/z1UMKqMN3VQ/video.html And with such a tutorial, you would have taught us all the practical real life use case of all Svelte and SvelteKit features, and their usage in a real world situation. Regards.

  • @gandalfgrey91
    @gandalfgrey91 Před dnem

    I was literally thinking of this same idea today, it makes more sense to download the actual components than to download it as a dependency. I plan on building my own web framework in Nim and I think I will port these components directly for my use-case.

  • @greggsworld4453
    @greggsworld4453 Před dnem

    They should have copied mobx more, this get and set context is silly especially if you dont have a singleton and you want to instantiate this class in many components.

  • @greggsworld4453
    @greggsworld4453 Před dnem

    This is how i used mobx in react

  • @tofu_u
    @tofu_u Před 2 dny

    I ran into an issue here at the 17:20 minute mark in that all the fields returned from the load function was undefined. I started digging into this and realized that what is returned from the load function is a promise, hence the +page.svelte renders all the content as undefined as they had not been resolved yet. I fixed this issue by making the load function itself be asynchronous: export const load = async ({ locals, params }) => { ... } This way "await" can be used inside and then I could simply do: const project = await getProject(params.projectId); return { project: project }; Not sure if anything changed here in SvelteKit or PocketBase as I tried copying copying your code from github first with the same issue. But this is at least a fix to guarantee that the data is resolved in the load function _before_it is passed to the +page.svelte. Just wanted to share in case anyone else gets stuck on this. And thanks one million times for this fantastic series. I'm a huge Svelte fan and I absolutely love how PocketBase meshes with it, beautiful technology and this tutorial masterfully showcases it. Keep up the good work!

  • @ondrejrohon5696
    @ondrejrohon5696 Před 5 dny

    Amazing lib and fantastic video, thanks!

  • @kristianlavigne8270

    Please make an updated video for use with Svelte 5. I'm unable to figure out how to use this with the new $props rune in order to transfer the correct form types. My form is simply "any" on the client.

  • @stoobe
    @stoobe Před 7 dny

    Great tips, thanks!

  • @O1O1OO1
    @O1O1OO1 Před 7 dny

    How will this work in Svelte 5?

  • @ranjithd277
    @ranjithd277 Před 8 dny

    Thanks for the video, I am trying to solve a scenario where I have a table with few number of records, each row has a check box with few buttons on page, update, delete etc. I am planning on pre populating form fields when user checks a row and hits submit. Any thoughts on how this binding can be done in svelte kit?

  • @Nisarsafi274
    @Nisarsafi274 Před 9 dny

    In my project json doesn't have ID Can I use title or description or else? Please tell me

  • @yt-sh
    @yt-sh Před 11 dny

    Good video 👏👏

  • @omargarcia7900
    @omargarcia7900 Před 12 dny

    Can you do a few videos on Keras and TensorFlow, please? :) Great content on your channel from what I've seen so far!

  • @TheStickofWar
    @TheStickofWar Před 17 dny

    I don't see the appeal here, I wouldn't have designed the card component like that to begin with. And with React we would've simply passed the components as props, so it isn't a new pattern. This actually makes Svelte take more effort to write, requiring you too package and dump components as properties.

  • @thejonellwood
    @thejonellwood Před 17 dny

    Not sure why but in displaying the project routes>projects>[projectId] everything was showing as undefined although it would console.log. So I added const project = await getProject(params.projectId) call after defining the function and then returned project: project.project (just terrible terrible code) but it displayed as expected after that. Maybe this helps if someone else hits the same issue.

  • @thejonellwood
    @thejonellwood Před 17 dny

    FACT: Thumbnail is the hardest word in the English language to type.

  • @d4yno
    @d4yno Před 18 dny

    I'd love a video about the snippets you briefly mentioned. Whats the best practice?

  • @somebodyHereFor
    @somebodyHereFor Před 18 dny

    MAN, IDK HOW TO THANK YOU ENOUGH

  • @GriizzDev
    @GriizzDev Před 18 dny

    Any particular reason you don't just use a singleton pattern with the `getToastState` function? Inside the getter you could check if a ToastState class already exists in context and just return it. If non exists yet, this is the first call, and you create a new ToastState, set it to context, and return it. This way you would not have to consider when to use `set...` and when to use `get...`.

  • @nayandeepyadav8790
    @nayandeepyadav8790 Před 22 dny

    why not write data to servers disk, that would be faster than api call to redis to get the data

  • @jeffloucks4071
    @jeffloucks4071 Před 22 dny

    1. I like this approach 2. I like how many times you said toast

  • @liammcgarrigle
    @liammcgarrigle Před 23 dny

    svelte is amazing...

  • @mitchm7521
    @mitchm7521 Před 23 dny

    Hunta you are the best, wish you well dude <3

  • @Mandleaf
    @Mandleaf Před 24 dny

    As far as I understand why you should have buttons, links, etc. as reusable components (as you may want to have a concise layout across pages), I don't understand why you overengineered such a simple component as a card. In most cases, you don't have to create separate components for text, titles, etc. It not only makes the code a mess but also much more complex, which is something you should avoid. You could simply include everything inside the card.svelte. In my personal opinion, the file structure should be as clean as the code, without pointless components and scripts. But yeah, I get that you may want to keep a concise layout across your page, and you may want to apply some fancy text styling to each of your paragraphs - I get it, really. But it doesn't justify a component with just a <slot/> in it. You could just create a simple CSS class, import it globally in global.css so each page would have access to it (if you wish not to import it to every individual component). Or you don't even have to create classes, just apply the styles globally to each <p> tag under <main> or <body>, etc. My point is, if you train yourself to keep things simple and maintainable, you won't regret it later on. It is always simpler to edit global.css styles than searching for a specific text component across hundreds of them. Of course, you can always overwrite styling from your global.css inside your +layout or +page.svelte - it is still a 20x simpler, easier, and more maintainable approach. I'd just like to point out that I am not a professional Svelte (or any, in fact) developer. I have some knowledge, and I wouldn't call myself a 'pro'. I just do it as my hobby. You are very welcome to discuss it in the comments - I would love to hear your opinion (as a pro dev, whether you agree or not). Perhaps there is something I don't understand or see, please lighten me then. Thanks

  • @sivaramakrishnanr.7173

    what about using Promise.all()?

  • @justintime9720
    @justintime9720 Před 26 dny

    might look good in theory, but if you have an API call inside +page.server.ts it then event.url.pathname will show the API url, not the current page?

  • @nikolaip.9944
    @nikolaip.9944 Před 27 dny

    Makes one wonder whether we should stop using onclick handlers altogether then? Over 50% of traffic comes from mobile these days, fact.

  • @giannivullo4391
    @giannivullo4391 Před 28 dny

    thank you for the great work you are doing here and on the UI libraries you're working on !

  • @vinciarts
    @vinciarts Před 29 dny

    Hi, I find that, when I hit the back button on the browser, onOpenChange is not running (I console.log it but print nothing). Did you experience the same issue?

    • @vinciarts
      @vinciarts Před 29 dny

      Oh I found that issue on Github!

  • @mr_clean575
    @mr_clean575 Před 29 dny

    this makes me happy

  • @obrien8228
    @obrien8228 Před 29 dny

    anyone know if this still works with the latest 0.22.15 ?

  • @piano42
    @piano42 Před 29 dny

    9:32 this is some very complicated kinda over engineered code... Why don't you store the toasts in a record where the key is the id? Not sure if it's a good idea to mutate the array of toasts. No need to handle a map of timeouts then either...

  • @ishaanmalhotra3008
    @ishaanmalhotra3008 Před 29 dny

    This looks great! Really wanted a shadcn port in svelte. One question though, does this require sveltekit or can it work with just svelte(without kit)?

  • @AliYasir5247
    @AliYasir5247 Před měsícem

    i am having trouble setting it up. specially i have a user-table with id as a number

  • @good-dev-student
    @good-dev-student Před měsícem

    4 days no new knowledge Master 😢?!

  • @edwardspresume
    @edwardspresume Před měsícem

    for the setTimeout cleanup, would something like this suffice constructor() { onDestroy(() => { this.toasts.forEach((toast) => { clearTimeout(toast.timeoutId); }); }); } addToast(title: string, message: string, durationMS = 5000) { const id = crypto.randomUUID(); const timeoutId = setTimeout(() => { this.removeToast(id); }, durationMS); this.toasts.push({ id, title, message, timeoutId }); } removeToast(id: string) { const toast = this.toasts.find((t) => t.id === id); if (toast) { clearTimeout(toast.timeoutId); } this.toasts = this.toasts.filter((toast) => toast.id !== id); }

  • @thedelanyo
    @thedelanyo Před měsícem

    If passwordless supported?

  • @philidornews4055
    @philidornews4055 Před měsícem

    Awesome, this was so helpful! Thanks! Do you have a strategy for components too? For instance if you wanted to render markup conditionally in the main nav (like showing a login button if the user isn't logged in yet). How do you keep it reactive?

  • @insa1988
    @insa1988 Před měsícem

    Awesome 🎉

  • @genshian
    @genshian Před měsícem

    I dont get why you switched from Next.js to Svelte. You mentioned, to keep things more based in javascript to render out the charts, but I don't understand how Svelte really makes that much easier when you can do that in React. Mostly curious, because I like the separation of js vs. the jsx aspects and if the js is too large I'd just move it into a hook. I guess, I dont know enough about Svelte though.

  • @raghavendra6978
    @raghavendra6978 Před měsícem

    thank you!

  • @afish5581
    @afish5581 Před měsícem

    Helllo, just started with Svelte and worked through the tutorial. There is one chapter about props which does not recommend $props due to performance issues. Since you used them, how big of an issue is it really? Coming from React + TS I prefer the syntax used in this video but I am hesitant to use it.

    • @Huntabyte
      @Huntabyte Před měsícem

      The docs you're referring to are the Svelte 4 docs, which talks about `$$props`, not the single `$props` rune in Svelte 5

    • @afish5581
      @afish5581 Před měsícem

      Oh 😮 I see. Thx for clarification ❤

  • @thedelanyo
    @thedelanyo Před měsícem

    The if check in +layout.server.ts isn't it unnecessary?

  • @lasal7820
    @lasal7820 Před měsícem

    Awesome!

  • @couragic
    @couragic Před měsícem

    I can’t believe I’m still not subscribed to this channel 😮 FIXED

  • @stefanmichalsky-hirschberg1545

    This is so impressive, I wish I could use svelte at work.

  • @BonBaisers
    @BonBaisers Před měsícem

    As a senior architect, I will be always amazed how javascript community will always try to avoid a pattern that is easy to learn, efficient and SOLID : dependency injection. We all figured it out long time ago, but still another framework trying to reinvent the weel.

    • @JackoCribbo
      @JackoCribbo Před měsícem

      DI and error handling leave me perplexed too, it’s not necessarily a resistance to OOP/SOLID related as functional solutions seem to be snubbed just the same.

    • @Venyl
      @Venyl Před 26 dny

      I'm not as experienced as you, would you mind elaborating on this comment and explaining how dependency injection would work here?

    • @BonBaisers
      @BonBaisers Před 26 dny

      @@Venyl Well the setContext and getContext are literally a service registration and a service getter. Doing that way, is a missed opportunity to me. Why not use interfaces or types in TS to decouple the service implementation and the pages ? Why not get for free lifecycle options ? Why not have a simple file where you can register implementations instead of having them anywhere in the code. Imagine ToastService needs another service, like a NotificationService that can route a notification to Email or SMS, based on another service UserPreferences... you get the point. the setContext getContext pattern can become a nightmare. Testability is another factor.

    • @rafaelrocha3991
      @rafaelrocha3991 Před 25 dny

      tbh these principles aren’t really opposed to the inversion of control. you can setup the context as a DI container and apply standard principles to it. It’s just an implementation of an IoC container, nothing inherently related to “JS developers”, example check NestJS or Angular if you think JS ecosystem doesn’t have more standard implementation of DI/IoC.

  • @ppcamps
    @ppcamps Před měsícem

    I'm with mixed feelings about this svelte 5. It's looking like a lot with React ( I hate react ) But the content is great, btw

  • @joedunleavy841
    @joedunleavy841 Před měsícem

    I get an error "Cannot read properties of undefined (reading 'loadFromCookie')" when attempting to read 'loadFromCookie' from an undefined object. Suggesting that at the point where loadFromCookie() is being called, the authStore object or its method isn't properly recognised.

  • @user-krnujdp
    @user-krnujdp Před měsícem

    Great video, wow!