When & Where to Add “use client” in React / Next.js (Client Components vs Server Components)

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

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

  • @ByteGrad
    @ByteGrad  6 หลายเดือนก่อน +2

    👉 NEW React & Next.js Course: bytegrad.com/courses/professional-react-nextjs

  • @wei7360
    @wei7360 ปีที่แล้ว +27

    I’ve checked so many channels and this is the only channel the provides more intermediate tutorials. Subscribed !!!

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

    hey man , i just bought your course today. I think you have something special which distinguish you from other youtubers. you have a nice way of explaining, without letting us feel board. something else is that you explain multiple use cases for each scenario, which i can relate to and im sure others also can relate to. The third thing which is a bit weird but your voice is relaxing and is nice to hear 😂 unlike other people which might be screaming or talk very low tune. thanks man ,, the best course ive even purchased.

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

      Amazing, thanks and enjoy!

  • @satyak1337
    @satyak1337 3 หลายเดือนก่อน +2

    I spent many hours trying to learn server component. This is one the best video that explains basics with simple examples. Subscribed.

  • @yendar9262
    @yendar9262 ปีที่แล้ว +20

    Amazing explanation. I was surprised learning you did not have 100k+ subscribers. You'll get there soon enough.

    • @ByteGrad
      @ByteGrad  ปีที่แล้ว +7

      Thanks, appreciate it

    • @CGAR_420
      @CGAR_420 7 หลายเดือนก่อน +1

      ​@@ByteGradat 112k now 8 months later 🎉 you did it

  • @Brandonbrandon1408
    @Brandonbrandon1408 ปีที่แล้ว +3

    Bro literally explained whole nextjs concept in less then 10 mins❤❤❤

  • @robert-freaking-kovacs
    @robert-freaking-kovacs ปีที่แล้ว +5

    This video is so great, I always thought that putting my server components inside of client components, as "children", they would become client components as well. Thanks for the explanation.

  • @kelvenraymond8444
    @kelvenraymond8444 9 หลายเดือนก่อน +1

    Very clear, this is the only channel that provides clear information about this subject ! Thanks a lot !

  • @zaynelovecraft
    @zaynelovecraft 4 หลายเดือนก่อน +5

    I think it's important the emphasis the fact that "use client" declares a client boundary. And a big gotcha is the fact that you can't pass functions from a server component to a client component. You have to make a component that uses the "use client" directive and this component will render your other client component that needs to take a function as a prop. So keep in mind that a component that takes a function as a prop can only be rendered by another client component.

    • @greggles_b
      @greggles_b 4 วันที่ผ่านมา +1

      This is the fundamental thing I haven't seen anyone explain what it entails in terms of how we build NextJS apps from an architectural POV. (I've just come back to React on a new project, so still learning RSC).
      The beauty of NextJS was that it made it very clear: You have a page component that is stateful, does all the data fetching and contains all the behaviour, which you can pass down to dumb, presentational components as props, i.e. state and callbacks.
      Now with RSC, you can't pass callbacks from a server- to a client-component. The solution given is always just to push down the callbacks into the client component which means to introduce another client component to wrap the presentational comp (what would otherwise be sufficient before on its own).
      RSC are much more like Angular1 IMO, a multi-paged app with islands of interactivity than any version of React (post-SPA) I've used before. Crazy how things go full circle

  • @judemusyoki7052
    @judemusyoki7052 ปีที่แล้ว +7

    Man you cleared some issues I was having with Next 13, thanks man. Your channel is definitely going to grow

  • @mehdisadeghian3984
    @mehdisadeghian3984 5 หลายเดือนก่อน +2

    Simple, Clear, and Short Video, @ByteGrad perfect job

  • @ankursaha9133
    @ankursaha9133 ปีที่แล้ว +4

    These were the exact doubts I was having since I learnt the basics of nextjs, thank you so much

  • @MEIYANG-sj2sb
    @MEIYANG-sj2sb 6 หลายเดือนก่อน

    thank you sooooo sooooo much, I was confused for the 'use client' for weeks and you explained in a clearly and easy way to understand!

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

    Love the simplicity of Next, I still haven’t found a way to use Material UI on my frontend w/out having to convert to client components

  • @aimenmansouri7648
    @aimenmansouri7648 ปีที่แล้ว +6

    You answered a question I had in my mind for several days. Thank you for the clarification. By the way, your method of explanation is excellent

  • @dan_b8982
    @dan_b8982 ปีที่แล้ว +1

    Fantastic explanation of the difference between the render and provider tree - never even occurred to me

  • @martintaanlee
    @martintaanlee 8 หลายเดือนก่อน +1

    This is a great explanation, so helpful - thank you!

  • @SarathChandran96
    @SarathChandran96 ปีที่แล้ว +1

    Clear explanation. you have a bright future in teaching brother

  • @humbertogarcia9404
    @humbertogarcia9404 11 หลายเดือนก่อน +1

    Thanks for the explanation ByteGrad, I could understand everything. Now I can keep forward on my path.

  • @mikevarela2741
    @mikevarela2741 ปีที่แล้ว +3

    Big thanks for the explanation. Especially the deeper explanation of context and the duality of the button in server vs client components. Not sure why this has been confusing but it’s making sense now. Question. Could we put the ‘use server’ pragma on server components to force a build error during dev?

  • @AdityaSharan811
    @AdityaSharan811 ปีที่แล้ว +1

    Thanks i was looking for some intermediate level tutorial
    Keep posting contents

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

    Best explanation ever.

  • @valenciawalker6498
    @valenciawalker6498 4 หลายเดือนก่อน +1

    Great explanation. New to next.js.

  • @introvertedbot
    @introvertedbot 11 หลายเดือนก่อน +1

    Man, your videos are helping me so much, thanks a lot

  • @dokkenrox
    @dokkenrox 16 วันที่ผ่านมา

    I think that some of the confusion with React server components revolves around that fact that the API is not very explicit. Components can get opted into client side rendering implicitly and the developer simply has to memorize these rules in order to avoid issues. The same could be said for issues with pages being automatically opted into dynamic rendering in Next.js. I've noticed that more recent versions of Next.js and ESLint have started warning more about client/server pitfalls. This definitely helps but my feeling is that they're trying to pick up the slack for what are probably just shortcomings with the API itself.

  • @chiho8119
    @chiho8119 ปีที่แล้ว +1

    Clearest explanation

  • @Kyle-rf5mb
    @Kyle-rf5mb 10 หลายเดือนก่อน +1

    Good explanation after checking a few other videos this one is clear and to the point.

  • @augedoo8409
    @augedoo8409 10 หลายเดือนก่อน +1

    Superb explanation. Thank you.

  • @owenz1500
    @owenz1500 ปีที่แล้ว +3

    Thanks for sharing. I’m using a third party UI library, Chakra UI, in my project. And seems I have to make all my components as client components in order to use this library. Does anyone have any solution for this, or any alternatives I can use?

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

    This is such a great explanation of this detailed situation! Are there dev tools available to help indicate when and where components become client components maybe unintentionally? Like something that labels the server and client components or warns you when the app is changing the server components to client components?

  • @artursavchuk2363
    @artursavchuk2363 10 หลายเดือนก่อน +1

    I thought that providers make their children as "use client" too
    Thanks for the explanation! ❤

  • @dawid_dahl
    @dawid_dahl ปีที่แล้ว +1

    Extremely useful video. Thank you!

  • @kidreative
    @kidreative 6 หลายเดือนก่อน +1

    thank you so much.. it helps me loads bro..

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

    This is really helpful. Thank you so much!

  • @MatheusJimenez-u4r
    @MatheusJimenez-u4r หลายเดือนก่อน +1

    dude, i`m amazed! gj

  • @geosystems2106
    @geosystems2106 ปีที่แล้ว

    I was always unsure about what runs in server and what runs in client. Unfortunately, this video did not really solve that question mark, at least it gave me a thread to follow : "use client". Thanks !

  • @mDHARYL
    @mDHARYL 6 หลายเดือนก่อน +1

    Thanks, now this helps me solve my problem

  • @alibinnaseer
    @alibinnaseer 11 หลายเดือนก่อน +1

    I learned soo much. Keep creating

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

    This should be the first section of the NextJS docs
    My code worked perfectly... until I hit build, and it went to hell
    Thanks to your video now it works !!

  • @meka4996
    @meka4996 ปีที่แล้ว +1

    Amazing! You are the man!

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

    Assuming the following is true:
    - a Button.tsx defines a button components
    - has NOT "use client" specified
    - uses "onClick" props
    - is imported inside a client component (hence becomes a client component in that instance)
    - is used on a server component (hence should remain a server component in that instance)
    What happens with "onClick" on the server?

  • @whertd3784
    @whertd3784 29 วันที่ผ่านมา +1

    Great video!

  • @musicdudejoe263
    @musicdudejoe263 27 วันที่ผ่านมา

    I'm still confused as to what counts as needing the "use client", since you said here that forms can remain a server component, but forms generally have input boxes for users to type into, and those forms usually require some kind of state, so how would you do a form using a server component? Do you make each input its own client component so that the form is made up of smaller client components?

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

    @6:00 but now it's a button without much things todo
    I mean where is it reading data from?
    When/where would the form show a loading indicator & how would it know?

  • @undergroundmaster8
    @undergroundmaster8 ปีที่แล้ว +1

    Man thank you a lot for this explanation. Im created an app while respecting all the conventions and rules about Client and Server components but when I run “npm run build” it shows that every page Its rendering “server-side rendering at runtime”. What could be the problem?

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

    Great explanations, but in a real project, generally a button is designed to change state from the parent (so the parent is a client component too… right ?) how to manage with this ?

  • @fahadkazmi7567
    @fahadkazmi7567 7 วันที่ผ่านมา

    bytegrad on inspecting page view source of a server rendered page i am unable to see any html tags, can u help in this regard

  • @AndreasStraub
    @AndreasStraub ปีที่แล้ว +1

    Very well explained and really important to know! Thx for sharing

  • @eavoutdom190
    @eavoutdom190 ปีที่แล้ว +1

    Bro resolved my doubts 💀

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

    I have question about use client in your code yoy added use client on button component because use on click but when you want show counter in form when user click show preview of counter we should add use client on form as parent copmonent because of use state counter imagine this concept aboue huge copmonent in page fetch data ssr and pass data as props in to root component to show preview data and filter data is parent coponent give data as props need use client at the top?

  • @ujjwalsaini4570
    @ujjwalsaini4570 11 หลายเดือนก่อน

    I saw this line in the next.js documentation, according to this line children of the ThemeProvider will also become client components. Is there something different when it comes to children component pattern?
    /* "use client" is used to declare a boundary between a Server and Client Component modules. This means that by defining a "use client" in a file, all other modules imported into it, including child components, are considered part of the client bundle. */
    What does this mean with regards to your example in Blunder#2 ?
    Please excuse me if i am missing something obvious, kinda new to this.

  • @programmingbeat6646
    @programmingbeat6646 11 หลายเดือนก่อน

    I am currently developing a Next.js application that utilizes Django for the backend and Next.js server actions. In my workflow, I fetch initial data using a GET request and subsequently update it using a form. However, upon submitting the form, I observe that the initial GET request is re-run, leading to redundant server-side fetching

  • @AhmadHassan-hb3lb
    @AhmadHassan-hb3lb ปีที่แล้ว +2

    Great explanation

  • @tacolegs2833
    @tacolegs2833 ปีที่แล้ว +1

    Very interesting! I've watched your videos for a while and have always been curious about what color scheme you use! '

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

    So reading localstorage requires client comp?

  • @yumeileventhal3069
    @yumeileventhal3069 12 วันที่ผ่านมา +1

    Very cool!

  • @doguarunbayraktar
    @doguarunbayraktar 10 หลายเดือนก่อน

    Hey!, I have been watching your videos and I understand the difference between server vs client components but I need a hand to pass props from server to client. Usually I am trying to pass class objects like (Food, or FoodChoices) and it does not work. So how am I going to populate client components? Thanks.

  • @fhkodama
    @fhkodama ปีที่แล้ว +2

    Good job! Thanks!

  • @tunamusic2314
    @tunamusic2314 6 หลายเดือนก่อน

    what client-side interactivity means ?

  • @hey.............
    @hey............. ปีที่แล้ว +2

    Great video man, hope while releasing course, you will have country specific pricing.🤞🏼

    • @ByteGrad
      @ByteGrad  ปีที่แล้ว

      That's the plan!

  • @jellyfish1772
    @jellyfish1772 7 หลายเดือนก่อน +1

    Thank you so so so much

  • @zul.overflow
    @zul.overflow ปีที่แล้ว

    Hello, sir i want to ask about app dir.
    Is it only the `app` directory that make our component as a server component (by default)?
    What if i make a component inside directory ex: src/components/Test.tsx (not under the app dir hierarchy) but i don't put the 'use client' on that component;
    Is my `Test.tsx` become server component? or i have to move it under the `app` dir hierarchy?
    Thanks in advance

  • @Riot-Mafia-UP32
    @Riot-Mafia-UP32 7 หลายเดือนก่อน +1

    Thanks.

  • @Edgar-pu1lc
    @Edgar-pu1lc ปีที่แล้ว

    Can i render server component in client component using render props pattern ?

  • @asadmalik5075
    @asadmalik5075 ปีที่แล้ว +1

    Just one word WOW

  • @zmr-vn5hx
    @zmr-vn5hx 2 หลายเดือนก่อน

    what is your theme bro ?

  • @aymendrid646
    @aymendrid646 14 วันที่ผ่านมา +1

    10/10

  • @designerborhan3727
    @designerborhan3727 ปีที่แล้ว

    Your tutorial is outstanding. Take love form Bangladesh.
    if you can little explain slowly then we could better understand it. Because english isn't our mother language.

  • @Alex_2049
    @Alex_2049 10 หลายเดือนก่อน +1

    good job 😉

  • @divyangbargali1554
    @divyangbargali1554 4 หลายเดือนก่อน

    Dr. Eric berg teaching programming

  • @alexandersamokhin
    @alexandersamokhin ปีที่แล้ว

    What about button that needs to send a fetch request?

  • @ianc6418
    @ianc6418 ปีที่แล้ว +1

    great videos

  • @akshaykumargupta6530
    @akshaykumargupta6530 ปีที่แล้ว +1

    You are an OG ❤

  • @DeepakGupta-yx7vu
    @DeepakGupta-yx7vu 4 หลายเดือนก่อน +1

    Great 👍

  • @didarnawzad
    @didarnawzad ปีที่แล้ว +1

    Ur great ❤

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

    So many places where things could go wrong/unexpected 😅

  • @chesterxp508
    @chesterxp508 6 หลายเดือนก่อน +1

    GoodJob!

  • @PRANAVMAPPOLI
    @PRANAVMAPPOLI 11 หลายเดือนก่อน +1

    nice !!

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

    Close your eyes. Listen. It's Bao-Dur from KOTOR 2.

  • @kwayyk
    @kwayyk 26 วันที่ผ่านมา

    drink everytime he says component.

  • @gustavoefftin94
    @gustavoefftin94 8 หลายเดือนก่อน

    man, the guys who created this really messed up

    • @gustavoefftin94
      @gustavoefftin94 7 หลายเดือนก่อน

      @alaskandonut many this. One of them: I saw A LOT of developers confusing things due to this 'use client' stuff. It leads devs to think that the component will be rendered on client

  • @hadialsimsmani9859
    @hadialsimsmani9859 ปีที่แล้ว

    take a shot everytime he says component

  • @xxapoloxx
    @xxapoloxx 7 หลายเดือนก่อน

    Everything i have seen about react so far SUCKs, Nothing i have seen makes it better than WebComponents