Silly React Mistakes not to make (plus how to solve them)

Поделиться
HTML-код
  • Опубликовано: 2 окт 2024
  • Enroll to the Full Stack React Course 👇
    developedbyed....
    Ever wondered why your React components re-render more often than your wardrobe changes? 🤔 We've got you covered! We'll unravel the mystery of re-renders and reveal some hidden truths that'll keep your app running smoother than a buttered-up water slide.
    Next, we'll tackle the do's and don'ts of state and useEffect like a pro, so you can avoid those pesky pitfalls that even the best of us have fallen into. You might call it a "state" of enlightenment! 🤯
    So, grab your favorite snack, throw on your comfiest coding hoodie, and join us as we laugh our way through the most common React blunders and teach you how to fix them like a boss. And remember, sharing is caring - so don't forget to like, comment, and share this video with your fellow devs!
    Let's get our React game on point! 🚀
    🛴 Follow me on:
    Twitch: / developedbyed
    Twitter: / developedbyed
    Instagram: / developedbyed
    Github: github.com/dev...
    #programming #react #webdevelopment

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

  • @developedbyed
    @developedbyed  Год назад +31

    React is weird, hope this helped understand some of the render concepts in React and it's side effects. 🔥

  • @tomspatula616
    @tomspatula616 Год назад +33

    0:15 Number 1, && Operator (empty array's length is 0, which is falsy value but not for JSX that sees it as valid value)
    3:03 Number 2, React Re-renders (React component re-enders when its state changes, that means re-renders for its all child components and to prevent that use memo() function)
    9:20 Number 3, Side Effects (run Side Effects only in useEffect Hook)
    22:48 Number 4, Keys (when mapping over a list DO NOT use indexes as an id - they will change when new elements ared added to the array, NOR built into browsers APIs like crypto.randomUUID() - when page refreshes new ids are generated)
    26:17 Number 5, Updating State (do not rely on current state value for calculating the next one, reach instead for callback function that state setters have and set the state based on the previous state)
    Thanks Ed!

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

    I'm little suprised that You didn't mentioned that but instead of logical rendering with '&&'(and operator) we can also use the optional chaining operator '?'. Like that: {tweets?.map(tweet) => (code here)}. It will check if tweets constant contain mapped data on right side if not it will just short circuit and return with 'undefined' without throwing error.
    Edit: I have noticed now that His mic is floating, this is the magic of coding?(🤔)
    I wasn't ready for ending

  • @SL4UGHT3R
    @SL4UGHT3R Год назад +16

    I think you meant tweets.length > 0 at 2:55.

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

      That’s it! Hahaha

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

      Lol I checked the comments just for this XD

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

      Is tweets.length > 0 or !!tweets.length better
      I feel like the second one is cleaner

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

      @@ramyjaiemandroid according to me > will be better as it is more readable.

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

      Yeah man. Even i was confused 😂

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

    Nice video bro...btw would be able to make a full descriptive video of context Api with useReducer. Sometimes it gets pretty confusing. It would be a great help. Thanks bro, keep it up👍👍

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

    Since the array length is 0, the Array.map will not map anything. In this case, we no need to do the array.length > 0 checking right? instead, we just need to check whether the array is null, undefined or something else

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

    Thankyou so much. Learned many things. :)

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

    how about !!tweets.length && ...

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

      What does !! do? Single negation will negate the value but what does double negation do?

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

      @@paradoxify_ !! (double bang operator) double negates it,
      it first turns the 0 into a true, then it turns it back into false.
      In very simple terms, it changes the 0 (or any positive / negative value for that matter) to its corresponding boolean.

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

      @@ralkey Oh wow, didn't know it exists. Thanks for explaining.

  • @Popo-hr6gc
    @Popo-hr6gc Год назад

    Great content as always!
    What was the extension called for auto completion of useState/arrow function?

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

    can we use tweets?.map in the first issue?

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

    Great, 28 mins just flew. I like how you jumped right into the topic

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

    Thanks! 💯

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

    !!tweets.length is also valid

  • @napoleonampahjnr.6509
    @napoleonampahjnr.6509 Год назад

    @developedbyed what's the extension you use to auto complete the code??

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

    Crypto.randomUUID is not that problem, if u create service mappers(because BE developers are too lazy, to send u proper structure all the time)
    Also about 27:25, it's good to be mentioned that why React set count to 2, because it's batching all the setState/dispatch operations

  • @ZahidHussain-hj2dk
    @ZahidHussain-hj2dk Год назад

    I want dev course as now I can't afford ......anyone can help me

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

    why not casting the items.length into boolean? !!items.length

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

    Thank you sir for teaching us for free,
    I want to learn and work with you.
    i have make all project that u have made,,,and even more.,, I am student of 2nd year...and please tell how can i grab internship.

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

    Would it not be good, to have the memo behaviour as default behaviour?

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

    I m downloading this video locallyyyyyy..... ⬇

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

    What is used to have those emoji window at 5:40?

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

    What is the extension for emotes

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

    Thanks @developedbyed for this info👍🏿👍🏿☺️

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

    Is this all done in NEXT JS App directory?

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

    What's the song in the background Ed? So relaxing and nice to study 😇

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

    Waiting for the Fireship comment!

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

    Thanks a lot for the video. It is very informative. On a different note, may I ask what theme and font you are using for your VS code?

  • @GamePlays-oj2mb
    @GamePlays-oj2mb Год назад

    Very informative, thanks for awesome video

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

    What an absolute gem of a video! I'm a front end junior and I feel so called out by some of the things you showed haha. Thanks to you I know how to avoid making them!

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

    This video was very much needed, thanks for putting up with this good work!🎉

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

    Idk but everytime see ur video, it makes me wanna learn again

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

    I believe your fix for tip #1 does not work. While using 'tweets.length < 0' works for the empty case, adding tweets back still won't render anything.
    My solution to this is just to use 'tweets.length > 0 &&'

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

    Great content Dev. I believe most devs have faced similar issues several times!

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

    But...but... chatGPT told me to rerender at the root....

  • @subramanyam.d24m56
    @subramanyam.d24m56 Год назад

    Thanks a lot for providing.

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

    Awesome video - thank you ❤

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

    Should I use memo() to wrap all my components then? In case they're children components of another component which will re-render very often?
    And should I use useId() hook when there's no unique id in arrays?

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

      I think you should Use memo only when necessary, don't make react do extra work checking the condition

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

    Amazing❤

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

    Thank you 😊

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

    ❤❤

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

    How did you add fire emoji ?

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

    The silliest mistake of them all is using react

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

    third comment here!!!

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

    Should be tweets.length > 0

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

    In my opinion, a better way to fix "tweets.length" being 0 is by using the double bang operator (!!),
    by typing "!!tweets.length" you are converting the 0 to a false,
    so there is no need to put a "