All 17 React Best Practices (IMPORTANT!)

Поділитися
Вставка
  • Опубліковано 1 лют 2025

КОМЕНТАРІ • 201

  • @trixn4285
    @trixn4285 6 місяців тому +394

    We banned almost all margins from our styles and it is a blessing. It's (almost) always a bad Idea to add a margin to a component to "create spacing". When there needs to be space between components we always use flex containers with a gap defined between the items. We found that this is very consistent with how a designers thinks about the design and it makes components easily have different spacing in different contexts. The spacing between items should always be defined be the parent, not by the items themself.

    • @TheDiegolopez007
      @TheDiegolopez007 6 місяців тому +11

      That's a very, very interesting argument. I'll have to dig deeper into that because I have run into issues due to margins.

    • @hoaxygen
      @hoaxygen 6 місяців тому +9

      I do this and it's so effective.

    • @dncdan
      @dncdan 6 місяців тому +16

      This concept of ditching the margins from HTML I believe was first made popular by Max Stoiber in 2020 in the article "Margin considered harmful", a read which I recommend to anyone interested in the idea. There's also a video by Theo Browne, former Twitch developer, titled "The Horror of Margins in CSS" in which he ellaborates a bit more on the problems of margin, and Adam Argyle's (Chrome CSS Developer Advocate) prediction that the usage of margin will decline as the gap property becomes more widely adopted in all-flexbox-and-grid situations. Highly recommend these.

    • @Brunoenribeiro
      @Brunoenribeiro 6 місяців тому +8

      Agreed! Spacing is a parental task 😁

    • @trixn4285
      @trixn4285 6 місяців тому +3

      @@dncdan Good pointers, must read for people that need to implement reusable components. A margin is basically a side-effect that breaks composability and react is all about composability. We have yet to encounter a layout requirement that can't be implemented using just padding and flex/grid + gap. It becomes second nature fast and you will almost guaranteed not look back.

  • @Khoaky
    @Khoaky 5 місяців тому +33

    This is by far the best practical educational video I’ve ever watched. I’m a senior CS major, and if I had videos like this sooner, I’d have 20x the experience I need.

  • @kasske1
    @kasske1 4 місяці тому +9

    I like how straight to the point you are. I am senior frontend dev, but i just purchased your course for support. Keep it up :)

    • @ByteGrad
      @ByteGrad  4 місяці тому +2

      Awesome, appreciate it! Enjoy

  • @mmmhbarcelona4560
    @mmmhbarcelona4560 6 місяців тому +21

    I'm going to get a job as a front end developer and I wanted this video exactly right now, thanks man!

    • @okkashaally2115
      @okkashaally2115 5 місяців тому +1

      How did it go buddy?

    • @darelbvcr687
      @darelbvcr687 5 місяців тому +5

      tech market sucks atm m8, good luck tho

    • @mmmhbarcelona4560
      @mmmhbarcelona4560 5 місяців тому

      @@okkashaally2115 Not that great, i sent my resume to 5 or 6 companies and half of them rejected it, and half of them didn't even read. And the scary part is my university is going to start very soon. i don't know what to do...

  • @bahramiwd4812
    @bahramiwd4812 6 місяців тому +12

    UA-cam lacks these kinds of videos! Because they're so awesome! 😃 Good job ByteGrad!

  • @rjwhite4424
    @rjwhite4424 6 місяців тому +6

    This video was awesome. I didn’t even notice that it was over an hour I was so interested. Can’t wait to try and put these in practice.

  • @mzafarr
    @mzafarr 5 місяців тому +4

    Loved it! Need more "best practices videos" about different stuff. Thanks!

  • @xor_r0
    @xor_r0 3 місяці тому +5

    Wish this video was available back when I started with React. I had to learn all the things shown here the hard way. Nevertheless, I enjoyed it very much. Keep up the good work!

  • @aj_mints8973
    @aj_mints8973 6 місяців тому +12

    As a Jr dev that came from a boot camp, I really appreciate this advice. The library folder with your utils, types, and hooks is a new concept to me. Learning about the Children pattern to avoid prop drilling is an idea I never knew about. I saw {children} being used in applications but never understood it before. Still got half way to go in the video, but I really appreciate your advice so far! The application I have been building for the past few months will benefit greatly from these ideas!

    • @dncdan
      @dncdan 6 місяців тому +2

      Good luck on your journey learning React!

    • @nicholas6497
      @nicholas6497 6 місяців тому

      Simply just looking at the source code of well-respected open source projects (e.g. the Node.js official website) helped me to learn immensely. A lot of times when I implement a new feature I do searches of terms or packages on GitHub to see how other people do it (e.g. I did this for the web-vitals library recently - how do others implement that package?). Then you can take the parts you like from how others do it and fit it to your own needs.

  • @xReDxTuRtLeZx
    @xReDxTuRtLeZx 2 місяці тому +1

    watched this on/off for a week while having down time and it was well worth it. quite a long vid but you really do cover so much of the fundamentals. im glad i follow a couple of these rules already but i have like 12 more to improve on lol. also somehow never noticed i could use two useEffects back to back. i dont think it came up, but will look to see if i can separate some

  • @hugosandsjo
    @hugosandsjo 3 місяці тому +1

    This might be the most useful React video ive seen. Great work!

  • @arturkunzmindset
    @arturkunzmindset 5 місяців тому +3

    20:31 about making the main tag and the div surrounding everything, a component: You could make a component, that takes childelements and displays them, so that you can still have the internal stuff in the App.tsx file.

  • @chess4964
    @chess4964 6 місяців тому +2

    On components which is topic number 3, for the main tag which is the container of the different components (Header, TodoList and Sidebar) you can also create a new component for it and just put it on the same file, just pass the 3 sub components as children so it is still visible, and cleaner to read.

  • @roberto9369
    @roberto9369 6 місяців тому +9

    wow. this is useful even if you have years in this. i have 8 years developing, I'm considered senior in my job, and this tips are very valuable, accurate and helpful. thanks

  • @friedricht3908
    @friedricht3908 6 місяців тому +67

    Very nice video, ByteGrad. What about making a video on how you test your react & nextjs applications ?

  • @CodeMouse_222
    @CodeMouse_222 3 місяці тому +2

    Thank you so much for this video! It is incredibly helpful. We appreciate your work 😊🤝

  • @martinharyanto4465
    @martinharyanto4465 6 місяців тому

    This is real gold. Thanks for explaining this to us and showing every best practices with example. This is very helpful in may ways. ❤👍

  • @ahsanmughal3806
    @ahsanmughal3806 6 місяців тому +2

    Amazing. I want more best practices like this.

  • @kim92se64
    @kim92se64 6 місяців тому +2

    Sir, You make always a great tutorial ! Awesome work

  • @olileach7536
    @olileach7536 5 місяців тому +1

    The level of this course is perfect. Simply explained but covers the detail needed. Do we have github repo available so we can look at the code?

  • @VankataKisyov
    @VankataKisyov 3 місяці тому +2

    Great video! You are sharing very useful information. Thank you!

  • @iamparmjeetmishra
    @iamparmjeetmishra 6 місяців тому +1

    Amazing Guide to all newbies. Thank you so much.

  • @larrytron1992
    @larrytron1992 5 місяців тому +1

    There were some really useful advice in video 👍 out of all the front end frameworks I've had experience with, React is by far my favourite

  • @nickwoodward819
    @nickwoodward819 3 місяці тому

    @19:15 - you might not be reusing them in the project, but it also makes reuse across projects easier :) Cool video, thanks!

  • @tomasbalducchi
    @tomasbalducchi 4 місяці тому +1

    Loved it, just great! Thanks so much for this.

  • @jasonwhittaker3940
    @jasonwhittaker3940 5 місяців тому +2

    Would love to see a video on good coding patterns to use in React or Next and also coding principles, like SOLID and more

  • @joe5head
    @joe5head 5 місяців тому +1

    Another one is using a progression of multiple useState-> single useState object -> useReducer to manage a component that grows in complexity.

  • @dncdan
    @dncdan 6 місяців тому +1

    Some nice refreshers here, even for a seasoned developer. Oftentimes one might forget some patterns if one stays away from React for enough time. And the section on performance optimization is also valuable. Hopefully React will eventually streamline most of these manual memoization hooks and dependency arrays. They've always been a pain for everyone.

  • @JojoMoonJoo
    @JojoMoonJoo 3 місяці тому +2

    thank you for sharing this valuable information 🙏

  • @juanierace7542
    @juanierace7542 4 місяці тому +2

    Excellent content! 48:30 I have a doubt about this pattern, in that case the jsx inside the Sidebar component (same with the other cases) is just a div, with some styling, it is not actually a Sidebar component. Does that make sense? (I understand that maybe this approach is only possible on non-reusable components, and in this case we can ignore that the content inside the component is not complete.)

  • @mohdsahil226
    @mohdsahil226 5 місяців тому +1

    Best content!, I have learnt a lot! Thanks😀
    just one question
    if a parent component re-renders, the child component will also re-render. How can a children pattern prevent this behavior? Would you please explain? That would be a great help!

  • @googlemani
    @googlemani 5 місяців тому +1

    Great content. Learned a lot. Thanks for the video, cheers.

  • @the_fallen_knight5596
    @the_fallen_knight5596 5 місяців тому

    hi, you can use import classnames from 'classnames'; its a function that allows to merge classnames just like your cn function

  • @MattElisa97
    @MattElisa97 6 місяців тому +1

    Thank you for this video!!!
    It is very practical.
    I like the way you explain things. More videooos

  • @seelvek6550
    @seelvek6550 5 місяців тому +1

    Thank you Wesley! Very much appreciated! 🙇

  • @sanchitbajaj02
    @sanchitbajaj02 4 місяці тому +3

    Great video, btw what VS Code theme is this?

  • @saveriomazza7781
    @saveriomazza7781 6 місяців тому +1

    the kind of videos that are really useful!

  • @kapxapot
    @kapxapot 23 дні тому +1

    A good one, thanks! Maybe only 1-2 points were new to me, does it mean that I am already good at React? 😅

  • @caceresjuan
    @caceresjuan 6 місяців тому +1

    Really good content man!

  • @dominikfrackowiak4693
    @dominikfrackowiak4693 3 місяці тому

    Regarding an example you use to illustrate rule no.4: within the component you have the logic that conditionally renders a button or buttons, depending on state (isAuthenticated). When I used this pattern at my job, my more experienced coworker called it an antipattern, because, in his opinion, it violates the Single Responsibility Principle. What pattern should we use in 2024 to separate that kind of logic from the component? Two components and a module with the logic?

    • @pairofrooks
      @pairofrooks 3 місяці тому

      Yeah for "login" and "logout" button components specifically the isAuth var check should obviously be within those components.

  • @AR-gx5yk
    @AR-gx5yk 5 місяців тому +1

    Thanks for this.
    great list

  • @echuderewicz
    @echuderewicz 5 місяців тому

    Thanks. Your explanations are clear and helpful.

  • @nickwoodward819
    @nickwoodward819 3 місяці тому

    @22:30 probably a skill issue, but I've always found that using props to apply styles always sounds great, but is annoying in practice - so like you've passed 'secondary', but what if you want that secondary button to change color at different breakpoints? sure, add media queries, but now your secondary button is coupled to the design of the page you're using it on.
    i often just find myself passing a larger tailwind class. shadcn even gets this wrong (as far as I can tell at least), not allowing classNames to override variant styles

  • @MrArod1207
    @MrArod1207 5 місяців тому +1

    Great video, thank you!

  • @rishikeshdasappa9951
    @rishikeshdasappa9951 4 місяці тому +1

    You're the best man
    I love your videos

  • @theoriginators1882
    @theoriginators1882 6 місяців тому +1

    Awesome video, loved it :)

  • @olusanyaolamide9764
    @olusanyaolamide9764 5 місяців тому +1

    Thanks Byte Grad for your contents

  • @devinlauderdale9635
    @devinlauderdale9635 4 місяці тому

    @ 1:04:59 why not just create your handler functions outside of your component function and use dependency injection to inject the setter function in?

  • @personalGoogle
    @personalGoogle 5 місяців тому

    One questions to the H1 class issue chapter 5:
    I’ve always used template literals to add classname props like

  • @-ARahulAkubattini
    @-ARahulAkubattini 6 місяців тому +1

    At 32:24 can't we use back ticks `${}` instead of seperate utility function ?

    • @Elias-zn6og
      @Elias-zn6og 6 місяців тому

      I had the same question, but I think it's not going to work to pass className props to tailwind className.

  • @osmanogluenes
    @osmanogluenes 6 місяців тому +1

    Great video, thanks 🔥

  • @anastasiosstefanou9658
    @anastasiosstefanou9658 5 місяців тому +1

    Great content!

  • @mentoriii3475
    @mentoriii3475 4 місяці тому

    it's a good practice to handle modals in the child component to prevent re-rendering other childs if you open it on parent component

  • @flavienbernard8132
    @flavienbernard8132 6 місяців тому +1

    This video is a real gem! Thanks for all the tips! It will help a lot of people to use cleaner practices.

  • @TakeOnMe5
    @TakeOnMe5 5 місяців тому

    1:03:56 As we learned from you before, it would probably be better to use [todos.length], due to the value / reference difference, right?

  • @mamunurislam6373
    @mamunurislam6373 3 місяці тому +1

    thanks for
    best tutorial

  • @skl9942
    @skl9942 Місяць тому

    I don't understand how saving input value in state is considered best practise. Why do you want to rerender on every keypress when you have access to the formdata on the submit event?

    • @ayushmishra-sw4po
      @ayushmishra-sw4po 4 дні тому

      Can u tell me what is the best way to do this ?

    • @skl9942
      @skl9942 3 дні тому

      I try to stay away from saving formdata in state unless I absolutely have to and use the submit event formdata.

    • @skl9942
      @skl9942 2 години тому

      I can't say that is the best way, that's why I asked 🙂

  • @EmiliyanTodorov-h1w
    @EmiliyanTodorov-h1w 5 місяців тому +1

    you give a lot of food for thought

  • @tomasburian6550
    @tomasburian6550 6 місяців тому +5

    Good stuff, even for more senior devs.
    I can't imagine coding anything without TS. Still very surprised someone out there makes tutorials without it.

    • @jasonwhittaker3940
      @jasonwhittaker3940 5 місяців тому +1

      Typescript can be a pain sometimes, when you are trying to get something out the way, you want to scream leave me alone; but it improves yourself as a developer as you add an extra layer to how you think when you are creating something. Like yourself, I too get frustrated when I see tutorials without it.

    • @tomasburian6550
      @tomasburian6550 5 місяців тому

      @@jasonwhittaker3940 When you're working in a team on a bigger project, I'd say TS is essential. I was just helping out on a project that was written only in JS and it was hell, debugging was a true ordeal and without TS you don't even have fully functioning intellisense, so it's good to use it imho.

  • @diamantisufi7938
    @diamantisufi7938 5 місяців тому +1

    Hi man! What are you using for AI autocomplete?

  • @TheShifu13
    @TheShifu13 2 місяці тому

    Regarding component folder structure - I kinda like doing Atomic Design Patterns

  • @StuartLoria
    @StuartLoria 4 місяці тому +1

    This is exactly what I am looking for

  • @cslearn3044
    @cslearn3044 6 місяців тому +3

    Your voice sounds great ngl

  • @Nguyenang-mo7tw
    @Nguyenang-mo7tw 6 місяців тому +2

    What theme you use

  • @josephito27
    @josephito27 5 місяців тому

    Love your content man

  • @napoleonborntoparty5437
    @napoleonborntoparty5437 5 місяців тому

    1:35:43 by the way conditional display of StartScreen component better to move from view to separate variable in component

  • @aymenbachiri-yh2hd
    @aymenbachiri-yh2hd 5 місяців тому +1

    Thank you so much

  • @XxbankerboomxX
    @XxbankerboomxX 6 місяців тому

    At 55:41 did you mean to put the form event in the arguments and not todocontent?

  • @oussamaboumaad4613
    @oussamaboumaad4613 5 місяців тому

    if you have flex use gap, easy tip to add spacing between components. no need for extra coding or anything.

  • @yashsolanki069
    @yashsolanki069 6 місяців тому

    At 21:00 i see that we are using inline styles but doesn't it them makes it difficult to fix something if a component is deeply nested and on the devtools we just see styles defined but don't know in code where the component is. Is there a way better way to manage tailwind??

  • @nyahhbinghi
    @nyahhbinghi Місяць тому

    what is the contexts folder for?

  • @ramiov3862
    @ramiov3862 6 місяців тому

    Great video,
    but in 1:24:00 i am confused about the todos in the useEffect depndency array
    todos is an array meaning its an object type not a primative type
    and my understanding is useEffect can know if primative value chnaged but cannot know if a object value chnaged
    so it will always run on each render in this case sense the todos array is an object type not a primative type
    please correct me if i am wrong
    and keep up the great work ❤

    • @pairofrooks
      @pairofrooks 3 місяці тому

      for aggregates like array and object it looks at the reference i.e. memory pointer, not the values within the array or object.
      (Although in useState([]) a new empty array is created on every re-render and passed into useState, it isn't actually used on any but the first render. )

  • @ThisIsMonta
    @ThisIsMonta 5 місяців тому +6

    0:05 we really need to do what ?

  • @waleedsharif618
    @waleedsharif618 6 місяців тому

    If you make everything its own components then when you want to test them for example using React Testing Library then there are too many components to test ? Wouldnt it be more complicated to test ?

  • @Applecitylightkiwi
    @Applecitylightkiwi 5 місяців тому

    I have a questions. Is it possible that in the H1 component destructure className = ‘ ‘ like this and pass it into the other tsx file ? 33:20

  • @27sosite73
    @27sosite73 6 місяців тому +1

    thank you, mate

  • @roberti1290
    @roberti1290 6 місяців тому

    Isn't it better to have a folder of them? For example, when I do nextjs projects, I create a folder called actions in that directory with all actions related to that route, is that good a practice?

  • @AaronIanWilson
    @AaronIanWilson 4 місяці тому

    What theme and extensions are you using in this video?

  • @sa4ita
    @sa4ita 5 місяців тому

    1:25:41 Not sure whether it is a good idea to use array (reference data type) as dependency in useEffect

    • @pairofrooks
      @pairofrooks 3 місяці тому

      Although in useState([]) a new empty array is created on every re-render and passed into useState, it isn't actually used on any but the first render.

  • @u9s0e9r
    @u9s0e9r 5 місяців тому

    What if instead of creating a button component you just create a style in css? I think it makes more sense? The buttons do have the same design but their usage differ, so I would assume it’s the case of creating a css class to button…?

    • @owaisahmed7820
      @owaisahmed7820 5 місяців тому

      Yes, it's mainly css which handle designs but you have different variants of buttons and conditionally apply classes on button. We have variants such as style, size, icons etc

  • @HemstitchedIrony
    @HemstitchedIrony 6 місяців тому

    Another option for #13 is just keeping track of which item is selected with a boolean inside the primary state, such as adding active: true to the selected object, especially if you are keeping track of multiple selected items, little more complex but a good solution compared to using an array of Id's. Great video, very informative.

  • @MiladJoodi
    @MiladJoodi 6 місяців тому +1

    Nice, Thank a lot.

  • @musicdudejoe263
    @musicdudejoe263 3 місяці тому

    1:21:30 how do you access URL query params?

    • @musicdudejoe263
      @musicdudejoe263 3 місяці тому

      ua-cam.com/video/ukpgxEemXsk/v-deo.html found it

  • @kiritokazuto9793
    @kiritokazuto9793 3 місяці тому

    31:00 why use utils when we can do className={`default-styling ${className}`}

  • @TheScottShepard
    @TheScottShepard 5 місяців тому

    What’s wrong with using a global CSS file for things like h1? Then you can just add className without all the machinery. Why do Tailwind users seem to avoid all css? What’s the science or philosophy with these practices? Thanks!

  • @PaulNegoescu
    @PaulNegoescu 3 місяці тому

    Why don't you keep your state, types and hooks relevant to only one feature together? I found that working on a feature and having to find related files across the folder structure is very jarring and slow. If you have a feature folder and have everything together, possibly with a naming convention for files, it shortens your lookup time considerably.

  • @deepmane5845
    @deepmane5845 5 місяців тому

    nextJs + Rtk = serverside or client side video please
    if we dont use rtk how to write code for CRUD in Nextjs for same app
    if we use rtk how to write code for CRUD in Nextjs for same app
    what is diffrence how to deal mega app in Nextjs

  • @azhardev9641
    @azhardev9641 6 місяців тому +1

    Nice guide. I mean I know it is gonna be nice.

  • @vramv9999
    @vramv9999 6 місяців тому +1

    Thanks

  • @Future_me_66525
    @Future_me_66525 6 місяців тому

    Is the classname needed to be so verbose or is best practice to leave it verbose instead of moving all the style to another file?

  • @regilearn2138
    @regilearn2138 6 місяців тому +4

    please consider REACT UNIT TESTING also your future videos

  •  5 місяців тому

    No github links in description? That's like the most important thing you can do.

  • @napoleonborntoparty5437
    @napoleonborntoparty5437 5 місяців тому

    46:49 props drilling not so bad, because we still have readability, on other side we put everything as children which looks like awful…Am I wrong?

  • @moofymoo
    @moofymoo 6 місяців тому +2

    nice to see how generic programming best practices translates to react because react components are just functions.

  • @ashmitsharma9096
    @ashmitsharma9096 6 місяців тому +1

    1:09:12 short recap

  • @sinanyilmaz9887
    @sinanyilmaz9887 6 місяців тому

    Why do you use typescript in a tutorial video without using its features?

  • @romainmt1777
    @romainmt1777 3 місяці тому

    Hep dear ByteGrad ! Thank you for your awesome content as always ! I don't think you'll find time to answer my newbie question so anybody knows what vscode theme he's using ? Thanks again for your videos !

  • @aurelienperia7082
    @aurelienperia7082 5 місяців тому

    Hello Guys, at 7.55 we can see he auto import the variable "max free todos". Can someone tell me how we do that ? Tanks.

  • @couragic
    @couragic 6 місяців тому +2

    My first thought was “why React 17? (Not 19)” 😊

  • @rsajdok
    @rsajdok 6 місяців тому +1

    worth watching