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

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

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

  • @ByteGrad
    @ByteGrad  7 месяцев назад +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 !!!

  • @satyak1337
    @satyak1337 4 месяца назад +3

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

  • @abdulrahmanmufarrah7883
    @abdulrahmanmufarrah7883 4 месяца назад +4

    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  4 месяца назад

      Amazing, thanks and enjoy!

  • @kelvenraymond8444
    @kelvenraymond8444 10 месяцев назад +1

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

  • @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 8 месяцев назад +1

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

  • @twerner5496
    @twerner5496 4 месяца назад +3

    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

  • @mehdisadeghian3984
    @mehdisadeghian3984 6 месяцев назад +2

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

  • @judemusyoki7052
    @judemusyoki7052 Год назад +7

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

  • @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.

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

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

  • @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 7 месяцев назад

    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!

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

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

  • @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

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

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

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

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

  • @Kyle-rf5mb
    @Kyle-rf5mb 11 месяцев назад +1

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

  • @martintaanlee
    @martintaanlee 9 месяцев назад +1

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

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

    Clear explanation. you have a bright future in teaching brother

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

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

  • @zaynelovecraft
    @zaynelovecraft 6 месяцев назад +6

    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 Месяц назад +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

  • @valenciawalker6498
    @valenciawalker6498 5 месяцев назад +1

    Great explanation. New to next.js.

  • @hassanfayed1427
    @hassanfayed1427 5 месяцев назад +1

    This is really helpful. Thank you so much!

  • @MatheusJimenez-u4r
    @MatheusJimenez-u4r 2 месяца назад +1

    dude, i`m amazed! gj

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

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

  • @adnanrruka5152
    @adnanrruka5152 5 месяцев назад +1

    Best explanation ever.

  • @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?

  • @augedoo8409
    @augedoo8409 11 месяцев назад +1

    Superb explanation. Thank you.

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

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

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

    I learned soo much. Keep creating

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

    Extremely useful video. Thank you!

  • @whertd3784
    @whertd3784 2 месяца назад +1

    Great video!

  • @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 !

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

    Clearest explanation

  • @artursavchuk2363
    @artursavchuk2363 11 месяцев назад +1

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

  • @nabilalhusail4731
    @nabilalhusail4731 3 месяца назад

    @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?

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

    Amazing! You are the man!

  • @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?

  • @mDHARYL
    @mDHARYL 8 месяцев назад +1

    Thanks, now this helps me solve my problem

  • @hey.............
    @hey............. Год назад +2

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

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

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

  • @yumeileventhal3069
    @yumeileventhal3069 Месяц назад +1

    Very cool!

  • @dokkenrox
    @dokkenrox Месяц назад

    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.

  • @dev_front
    @dev_front 4 месяца назад

    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?

  • @fahadkazmi7567
    @fahadkazmi7567 Месяц назад

    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

  • @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 11 месяцев назад +1

    good job 😉

  • @dctsdev
    @dctsdev 3 месяца назад

    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?

  • @musicdudejoe263
    @musicdudejoe263 2 месяца назад

    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?

  • @DeepakGupta-yx7vu
    @DeepakGupta-yx7vu 5 месяцев назад +1

    Great 👍

  • @AhmadHassan-hb3lb
    @AhmadHassan-hb3lb Год назад +2

    Great explanation

  • @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?

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

    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

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

    Ur great ❤

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

    Good job! Thanks!

  • @Mijdax
    @Mijdax 5 месяцев назад

    So reading localstorage requires client comp?

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

    You are an OG ❤

  • @jellyfish1772
    @jellyfish1772 8 месяцев назад +1

    Thank you so so so much

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

    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.

  • @HONjramiroz98
    @HONjramiroz98 4 месяца назад +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 !!

  • @tunamusic2314
    @tunamusic2314 7 месяцев назад

    what client-side interactivity means ?

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

    Bro resolved my doubts 💀

  • @Dlb645
    @Dlb645 2 месяца назад

    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 ?

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

    great videos

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

    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.

  • @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

  • @Edgar-pu1lc
    @Edgar-pu1lc Год назад

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

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

    GoodJob!

  • @Riot-Mafia-UP32
    @Riot-Mafia-UP32 8 месяцев назад +1

    Thanks.

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

    nice !!

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

    Just one word WOW

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

    What about button that needs to send a fetch request?

  • @zmr-vn5hx
    @zmr-vn5hx 3 месяца назад

    what is your theme bro ?

  • @aymendrid646
    @aymendrid646 Месяц назад +1

    10/10

  • @nabilalhusail4731
    @nabilalhusail4731 3 месяца назад

    So many places where things could go wrong/unexpected 😅

  • @divyangbargali1554
    @divyangbargali1554 5 месяцев назад

    Dr. Eric berg teaching programming

  • @kwayyk
    @kwayyk 2 месяца назад

    drink everytime he says component.

  • @eyeofthetiger7
    @eyeofthetiger7 4 месяца назад

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

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

    take a shot everytime he says component

  • @gustavoefftin94
    @gustavoefftin94 9 месяцев назад

    man, the guys who created this really messed up

    • @gustavoefftin94
      @gustavoefftin94 8 месяцев назад

      @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

  • @xxapoloxx
    @xxapoloxx 9 месяцев назад

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