Let’s end the discussion! "use client" vs "use server" Client or Server Component | Next.js

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 พ.ย. 2024

ความคิดเห็น • 24

  • @ibrahim_youssef_13.12
    @ibrahim_youssef_13.12 3 หลายเดือนก่อน +1

    Believe it or not, this very smart and very handsome young man has solved many problems and explained things that amounted to months of solving errors. Please continue and explain the use server and fetching data in a separate video, and follow all the problems in the next section in particular every code related to Next please.

  • @MarceloGuaycurus-o1k
    @MarceloGuaycurus-o1k 2 หลายเดือนก่อน +1

    Fantastic video. Claude 3.5 should watch this. It uses client components everywhere

  • @meetsuthar4118
    @meetsuthar4118 3 หลายเดือนก่อน

    I liked the way u explain hard topic is much simpler way. Keep it up bro !

  • @Luisllaboj19
    @Luisllaboj19 2 หลายเดือนก่อน

    Sorry for the big message in advance :c.
    IMPORTANT: Both Server and Client components are pre-rendered on the server at built time for the initial page load, that's why Client component loggs appear on the server console.
    Server components only run once, they do not re-render. Yes they can "re-render" if you request them again from the server but in that case it's more like they're "re-building" instead of "re-rendering".
    After the initial page load, Client components are only re-rendered on the client. What "use client" directive does is telling the Next.js bundler "send this chunk of code and everything that is owned by this file to the browser", which means if you import a component -- either a Server o Client component -- this code and everything under it will be sent to the client as well. This means you're essentially defining a boundary, and everything inside that boundary will run on the client.
    Like he said, Next.js treats all components as Server components by default, which means you need to opt out of that in case you need to use client-only features like React State, LifeCycle methods (mount, unmount, etc.), the window object and client-only APIs. Only in these situations you should be tempted to write "use client" at the top of the file, and you should try to do it only on very specific components, not the whole page.
    On the other hand "use server" is not the opposite of "use client", 11:40 NO, you CAN'T and you SHOULDN'T USE this directive on the top of a (default) server component, and certainly not on the top of a file that will be imported inside a "use client" boundary in order to make it run on the server again. "use server" directive tells the bundler "turn all exported async functions into endpoints, expose them for the client to use".
    Basically, "use client" means -> send this chunk of code to the client, either to hydrate or run client side APIs, and run on the client from now on.
    "use server" means -> "expose these async functions as POST endpoints to be hit". Only async functions are allowed in a file with "use server" directive at the top.
    WHY CAN'T SERVER COMPONENTS BE IMPORTED INTO CLIENT COMPONENTS AND REMAIN SERVER ONLY?
    When Next.js builds the app, it will run and render all server components first and then run and render the client components, if it encounters a client bouldary ("use client") it will execute that code once all the server components were rendered and turned into RSC Payload.

    • @tobitacklestech
      @tobitacklestech  2 หลายเดือนก่อน +1

      Wow 😯, nothing to add here, thank you

    • @Luisllaboj19
      @Luisllaboj19 2 หลายเดือนก่อน

      @@tobitacklestech No no, happy to help! Let me know if I can help with anything else :D

    • @tobitacklestech
      @tobitacklestech  2 หลายเดือนก่อน

      @@Luisllaboj19thanks a lot man! 🎉

  • @ajayrathod7438
    @ajayrathod7438 3 หลายเดือนก่อน

    That was very helpful thanks

  • @Lucifeier
    @Lucifeier 3 หลายเดือนก่อน

    Thank you for the video, btw what is the whiteboard app you are using now? That seem nice!

    • @tobitacklestech
      @tobitacklestech  3 หลายเดือนก่อน +1

      @@Lucifeier this was excalidraw, it is on the Web 🔥

  • @ayushshende4290
    @ayushshende4290 3 หลายเดือนก่อน

    Client would be very useful when you want to work with a custom backend like express or django

  • @pawatify888
    @pawatify888 10 วันที่ผ่านมา

    Which app did u use for explaining client server concept?

    • @tobitacklestech
      @tobitacklestech  10 วันที่ผ่านมา +1

      Excalidraw ;)

    • @pawatify888
      @pawatify888 10 วันที่ผ่านมา

      @@tobitacklestech Thanks Bro

  • @codeinspector
    @codeinspector 3 หลายเดือนก่อน

    Thanks :)

  • @hamoncordova7431
    @hamoncordova7431 8 วันที่ผ่านมา

    Why did you mention that client components can't be seen by web crawlers? Using SSG, for example, it's all client components. The final render is all the pre-rendered HTML, JS, and CSS, so web crawlers can see it as well.

  • @MetalPotionEhUmCu
    @MetalPotionEhUmCu 3 หลายเดือนก่อน

    who was debating about this?

    • @tobitacklestech
      @tobitacklestech  3 หลายเดือนก่อน

      There are always discussions about that, especially if you learn Next js 👀

  • @anhvuuc8693
    @anhvuuc8693 3 หลายเดือนก่อน

    verceo made nextjs harder 😂 they was the best of the best but now …

    • @tobitacklestech
      @tobitacklestech  3 หลายเดือนก่อน

      I think they still do a very Great Job, New Technologies just need new solutions 👀