Fullstack React Components - with no API

Поделиться
HTML-код
  • Опубликовано: 28 сен 2024

Комментарии • 88

  • @CodingSauce
    @CodingSauce Год назад +56

    This is easily my favourite RUclips channel right now, A+ content every time

    • @bhaumik3118
      @bhaumik3118 Год назад +4

      True, a legit goldmine for intermediate devs.

    • @suryawigunaa
      @suryawigunaa Год назад

      Agree, his explanation is something else.

  • @yantaosong
    @yantaosong 11 месяцев назад

    really appreciate it . Why are you so proficient in technical knowledge every time, and your examples are so concise and accurate? Keep going!Just one demo ,let me understand 3 concepts at least .

  • @alibayatmokhtari
    @alibayatmokhtari Год назад +5

    Your are amazing in presenting. Hoping a complete Next 13 crash course from you 💯

  • @pheisar
    @pheisar Год назад

    Its not enough making my favourite coding podcast, now also great yt content? So thankful

  • @VidozMusic
    @VidozMusic Год назад

    Once again, great video, Sam!

  • @sK4hsCz
    @sK4hsCz Год назад

    Cool video and nice explanation, but isn't this something like express with AlpineJS? I mean with this server actions you have no more animations and things like that. I'm pretty sure I'm missing something to fully get it right xD

  • @LauriePoulter
    @LauriePoulter Год назад

    Great video. I'm curious about state between 'renders' are you able to focus the input and save the scroll position?

    • @samselikoff
      @samselikoff  Год назад +1

      You definitely should be able to! You can call a server action from a client component so I think that would be my first step - making a client component.

  • @shafu_xyz
    @shafu_xyz Год назад

    hey how do you navigate vscode that quick? vim bindings, or anything else?

  • @dougyoshii
    @dougyoshii Год назад

    TOMA MEU LIKE

  • @asher-youtube
    @asher-youtube Год назад

    The form on the new post page stops revalidating the '/' path after its first use unless I refresh the app. The only fix I've found is to redirect to the homepage in the aftersave. Are you familiar with this issue?

    • @asher-youtube
      @asher-youtube Год назад

      this error shows up when i inspect the form after its been used at least once "throw new Error('A React form was unexpectedly submitted. If you called form.submit() manually, consider using form.requestSubmit() instead. If you're trying to use event.stopPropagation() in a submit event handler, consider also calling event.preventDefault().')"

    • @samselikoff
      @samselikoff  Год назад

      Hmm... I haven't seen this. I know the Next.js team is working on the caching behavior (removing some of it even) because it's causing a lot of confusion

  • @ashleyredman
    @ashleyredman Год назад +1

    Not sure how i feel about this

  • @icaro_rdp
    @icaro_rdp Год назад

    that's a willy-shaking tutorial

  • @tweney3452
    @tweney3452 Год назад +6

    The "use server" "use client" everywhere in code look shitty imo

    • @oscarljimenez5717
      @oscarljimenez5717 Год назад

      is not everywhere, just in the places you want to cross the client server bridge.

    • @arjundureja
      @arjundureja Год назад

      You can add "use server" to an entire file and it'll apply to all functions in that file

    • @tweney3452
      @tweney3452 Год назад

      @@arjundureja yeah but that's not the point here, if you want to use client and server component in same file you need to specify it (why using server and client component in same file ? Idk I think it's stupid xd). The new nexts js things is "Do all in the same file and fuck ". I think it's a shit idea.

  • @codinginflow
    @codinginflow Год назад

    I've been wondering how to make reusable server actions revalidate/redirect to different routes. That's a good solution! I could also pass the route I want to revalidate as a argument instead, couldn't I? Although that would not be as flexible.

    • @samselikoff
      @samselikoff  Год назад +1

      Yep definitely could 👍 And yes wanted to show the full function version just to demonstrate the extra flexibility

  • @0x834
    @0x834 Год назад +8

    Great explanation by example. It would be nice if you also show network tab so we can understand whats going on exactly behind the scene

  • @Delba
    @Delba Год назад +3

    Incredible explanation as always Sam!

  • @U-installet
    @U-installet Год назад +1

    Thank you Sam! You just saved me so much time

  • @merotuts9819
    @merotuts9819 Год назад +1

    So server actions are basically a replacement for *src/pages/api* routes ? Now we can write those handlers directly on our components simply with 'use server' ?

  • @madebyjonny7637
    @madebyjonny7637 Год назад +1

    I was having a play with server actions last week, but couldn't find an elegant solution for errors, i know its beta, but curious if you have thought about this?

    • @samselikoff
      @samselikoff  Год назад

      Haven’t tried it yet. I think you can use the result from an action if you await it in a client component. Set state with the result and display it in the component.

  • @giyoka2609
    @giyoka2609 Год назад +3

    top tier content as always , i wish we could do more framer-motion and next 13 content

  • @wotok7
    @wotok7 Год назад +1

    I love articulate pronunciation of Sam! Having English B1 allows to completely disable subtitles and dive into loved techs. Best wishes!

  • @ray-lee
    @ray-lee Год назад +1

    What if the server action throw an error?

  • @ersinbasaran
    @ersinbasaran Год назад

    I had divided opinions about server actions:
    - twitter says it is just back to old php days
    - "use server"s are bad, now we are doing them in the props of components in component returns??
    - (later..) ohh wait! now can I code a form which does what it is designed to do and put it anywhere in my project, any page, any other component, without specifically defining an api endpoint?
    I'm not sure if I bought Sam's prensentation or design decisions behind server actions. Yet, there can be some use cases here.

  • @ADVOLD-v9n
    @ADVOLD-v9n Год назад

    a bit of a dumb question, will server components work for ISR pages?

  • @jamesfoley4426
    @jamesfoley4426 Год назад

    Sam when you create the components folder with the file new post form at 1:42 in the video. Is that an extension your using or a quick key combo? Appreciate the video very much good stuff.

  • @jamesdenmark1396
    @jamesdenmark1396 Год назад +1

    I see some Ruby on Rails influence here, but I don't like how everything is mixed together. Is there a cleaner way to do it? It's funny to imagine David from Ruby on Rails and David from React talking about ideas!

    • @oscarljimenez5717
      @oscarljimenez5717 Год назад

      yes, they use ideas from PHP and Ruby on Rails, said it by the React and Vercel team.

  • @sagarsiwach7930
    @sagarsiwach7930 Год назад +1

    Chef, you gonna go a Million subscriber some day. 10/10 Content and Production

  • @hackmylife6268
    @hackmylife6268 Год назад +2

    Great explanation, just what i needed for this, however, i feel like while very convenient, no extra setup needed, and way less code, it's gonna be a nightmare to figure out debug on large code bases

  • @mistersir3185
    @mistersir3185 Год назад

    1:38 How did you use keyboard to navigate and create new folder? Never seen that before.

  • @joaomaia9140
    @joaomaia9140 Год назад

    Isn’t inputs a client components? Can someone explain I’m new to this subject

  • @TeenaCode
    @TeenaCode Год назад

    Nice video as always though 👌🏿

  • @jordantan888
    @jordantan888 Год назад

    does it mean we won't have server cold start if we use server action

  • @kevinbatdorf
    @kevinbatdorf Год назад +1

    A lot of magic happening that's going to bother a lot of people. I love it!

  • @jordancutler7552
    @jordancutler7552 Год назад

    cool but so scared about maintainability

  • @mukleshossen751
    @mukleshossen751 Год назад +1

    Love from Bangladesh

  • @nonefvnfvnjnjnjevjenjvonej3384

    anyway to avoid that key hack at the end to reset the form?

  • @technikhil314
    @technikhil314 Год назад

    front end frameworks are way too much competitive. just cherry picking most liked functionality from other frameworks is not going to help the frameworks gain more traction. IMO. WDYT?

    • @samselikoff
      @samselikoff  Год назад +1

      I don’t think it’s cherry picking.. what other framework let’s you fetch and render within the same JavaScript scope?

  • @yantaosong
    @yantaosong 10 месяцев назад

    I can't undersood the error, "Function can't be passed to clientcompoent unless... " , NewFromPost is a Client component ? I thought it is a Server Component, there is no 'use client' in it .

    • @samselikoff
      @samselikoff  7 месяцев назад +1

      Great question! Turns out is more or less a client component. React uses the new `action` prop to make a fetch() request from the client-side app. So, anything that's passed to it from the server needs to be serializable, since it ends up in the browser.
      If we had passed something like `loadMoreData()` to NewPostForm, then NewPostForm could have called that during render (i.e. `await loadMoreData`). That would have worked because it all would have happened on the server.
      So it's our use of that necessitates the prop to be serializable.
      Does that make sense?

  • @Imjoshnewton
    @Imjoshnewton Год назад +1

    I love the implications of this. Having concise, composable components that have their own backend logic is awesome for small teams, one man teams, or just teams who want to release features quickly.

  • @rockNbrain
    @rockNbrain Год назад

    Great job dude ! Tks a lot 🎉

  • @realitydesigners
    @realitydesigners Год назад

    wild

  • @dgcp354
    @dgcp354 Год назад

    this is just beautiful

  • @MikhailSlizh
    @MikhailSlizh Год назад

    Is it good practice to mix database logic with JSX in one component?

    • @linorabolini
      @linorabolini Год назад

      I don’t like that part either hmm I want to try it and see what happens tho

  • @krimod
    @krimod Год назад +1

    Amazingly well presented, thank you Sam !
    I wonder how this gonna affect all the blitz, trpc fullstack typscripty framework ?! looking forward to it

  • @mazwrld
    @mazwrld Год назад

    💙💙

  • @Mattkoso
    @Mattkoso Год назад

    So cool!

  • @mrgerbeck
    @mrgerbeck Год назад

    Couple points.
    "All these components are server components"
    The components under /components are isomorphic and you can use state there
    Also, if you add a delay to the form submit, there is a lag before the list of posts update--but that's not a great experience, we need a loading state. Ideally we'd have some loading state while wait. Can't do that without make an API call. Other frameworks like Sveltekit have streaming as well and also support a load state if the data is invalidated without having to write client side calls to the BE.

    • @samselikoff
      @samselikoff  Год назад +1

      All components (regardless of directory) are Server Components by default in Next.js 13.
      You could add a loading state in between the save and the call to revalidatePath. I should make a video explaining how to update the state of a client component in response to a server action completing.

    • @mrgerbeck
      @mrgerbeck Год назад

      @@samselikoff That would be interesting. I can certainly achieve it with useTransition; or other contraptions.
      Say you're taking 3 seconds to render a chart--and you have loading state for that chart. You then have link below the chart for previous or historical data (linking to the same page only with query params for the historical data).
      In Sveltekit, clicking a link that goes to the same page will cause the load state to show until the data is ready and the chart is rendered. This, because that data is sent via the streaming api, you need do nothing extra.
      In NextJS, the design choice I don't here is that if I click that link, there is a dead 3 seconds where nothing is happening. And then the data updates suddenly.
      The NextJS behavior is not too unlike a native web experience. And for that I can just use Astro, which is more performant. Your SVG chart with D3 should work with Astro as well; only with better performance.
      Having client UI loading state for users with JS turned on with nearly no additional effort is a big win for Sveltekit.
      Yes I can do this in NextJS (viz. useTransition, Suspense + compliment library or some Promise wrapper, etc.), it just seems to require a lot more boilerplate; unless there is some pattern for doing this with no additional effort--which I've not seen published anywhere yet. And using `redirect` within the Server Action reloads the layout.
      I can appreciate reloading all the data on a page just to update a chart vs client side logic to just load the data for the chart is likely more efficient; but requires a lot more work, like updating the browser state along with more code to ship and maintain. That said having a simple API and getting progressive enhancement on top of the web experience for free is the sweet spot.

  • @RegisZaleman
    @RegisZaleman Год назад +1

    Very clear explanations. Thanks!

  • @razdingz
    @razdingz Год назад

    What editor is being used here ? is is vim or neovim ?

    • @samselikoff
      @samselikoff  Год назад +1

      This is VS Code along with the Vim extension

  • @DrTechTips
    @DrTechTips Год назад

    Outstanding example and super clear explanation 👏. Thanks. I would appreciate it if you could share the example code on your Github repo. Thanks

  • @TeenaCode
    @TeenaCode Год назад

    The length at which the React folks have gone to explain this RSC thing and still, no one seems to get it is telling. 😅
    Dan is literally on the Bird app every day, with tweets after tweets after tweets..., still we're all just like "🫤"
    Either we're all too *dumb to understand this "revolution" or... 🤷🏿‍♂️

  • @alsherifkhalaf7385
    @alsherifkhalaf7385 Год назад

    Can we use this new approach to make classic authentication using JWT directly from server to cookies ?

  • @mruczekpln
    @mruczekpln Год назад

    mate, you are so underrateddddd. keep up with this excellent content!

  • @dougyoshii
    @dougyoshii Год назад

    sam, congrats for your content
    I ever learn a lot watching your videos
    tks!

  • @codewithmirko1651
    @codewithmirko1651 Год назад

    Best explanation with best example on server components for me.. i remember i was struggling a lot at the beginning to understand getstaticprops and getserversideprops but i now find this new model way easier to understand! Thx a lot for this video! Im subbed!! 🎉

  • @asher-youtube
    @asher-youtube Год назад

    Perfect guide - thank you! ❤

  • @jordondax
    @jordondax Год назад

    You're a natural, Sam! I feel like I'm really getting it now.

  • @tuanauduong
    @tuanauduong Год назад

    Could you create a video to share about your vim vscode setup?

  • @jimshtepa5423
    @jimshtepa5423 Год назад

    does it require server runtime to execute server code? if so, what runtime is it using in this example?

  • @CommunityAllSeasons
    @CommunityAllSeasons Год назад

    This is some quality content

  • @aBradAbroad
    @aBradAbroad Год назад

    Very well explained.

  • @nick-ui
    @nick-ui Год назад

    Server-side actions execution is cool! But let's think about the cost of these actions.
    The load on the server is growing, which means that the fee for this is growing.
    Executing the code on the client side will cost us less. What do you think about this?

    • @oscarljimenez5717
      @oscarljimenez5717 Год назад +8

      Nop, is the inverse. If you do server actions for example, if you mutate some data and wanna revalidate the cache. In old React or every other framework, you will have to mutate (1 request), wait the response and then revalidate the data (2 request). With React new model and server actions, you can do it in 1 single request. So you will end with less requests to the server (the same to the database), reducing the client-server waterfalls. Also giving the server more power to render html is better for user experience, because if you can send html, then the browser, server or CDNs can cache it, so it will ended in less request to the server.

  • @alexanderkuznetsov634
    @alexanderkuznetsov634 Год назад

    Mind-blowing )

  • @private_variable
    @private_variable Год назад

    @samselikoff Great video. However, could you explain how do you have access to `prisma` inside of server action in NewPostForm component without import it?

    • @khaledsanny4817
      @khaledsanny4817 Год назад

      Yeah great point am surprised too

    • @samselikoff
      @samselikoff  Год назад

      Should have imported it - it comes from how Prisma recommends setting up the client in Next.js apps due to hot refresh www.prisma.io/docs/guides/other/troubleshooting-orm/help-articles/nextjs-prisma-client-dev-practices

  • @SogMosee
    @SogMosee Год назад

    first comment! first minute!

  • @SogMosee
    @SogMosee Год назад

    Fuck, I lost