React JS Lists and Keys | Learn ReactJS

Поділитися
Вставка
  • Опубліковано 24 гру 2024

КОМЕНТАРІ • 84

  • @DaveGrayTeachesCode
    @DaveGrayTeachesCode  3 роки тому +12

    When you generate a dynamic list of elements in React's JSX, each element in the list needs a key attribute. This tutorial explores how to generate a list with the higher order function map() and apply the required keys to each element. In addition, this tutorial expands the project and builds out some additional functionality for the list items applying what was learned in the previous tutorials in the series. A link to the full Learn React playlist is above in the description. If you are new to Javascript, I recommend starting with my full 8 hour Javascript tutorial for beginners here: ua-cam.com/video/EfAl9bwzVZk/v-deo.html

  • @psyferinc.3573
    @psyferinc.3573 2 роки тому +4

    im actually grateful. this time when i felt stuck i looked for your series . im excited to see react differently through your teachings.

  • @fazzyakamello
    @fazzyakamello 3 роки тому +2

    Dave i can tell you’re a natural teacher. The way you explain reason why you do certain things makes so much sense to me. Kodus

  • @webdev644
    @webdev644 2 роки тому +3

    You have a knack for breaking down the complex things into simple ones. Really loved these lectures. Thank you very much

  • @zuhayeranzumfuad8721
    @zuhayeranzumfuad8721 2 роки тому +1

    I've found your channel today and have already cleared all my doubts. Your examples are way easier to understand. Thanks a lot.

  • @AmandeepSingh-sx9ke
    @AmandeepSingh-sx9ke 4 місяці тому

    Your explanation is very clear. Thank you for your videos. Dave

  • @jingli9232
    @jingli9232 2 роки тому +1

    your tutorial is top quality, extremely neat and to the point, helps a lot, great thx

  • @khaledbenshible2657
    @khaledbenshible2657 Рік тому

    it was rather complicate and not easy to learn but now im excited to see react differently through your teachings. It started to clear up little by little .great thx

  • @zakariachajia1199
    @zakariachajia1199 7 місяців тому

    I get more comfortable with react the more i advanced with this series

  • @KirtanPatel552
    @KirtanPatel552 День тому

    Thanks Dave Gray for This Informative Video ...

  • @umarilyas692
    @umarilyas692 2 роки тому +1

    Every thing is explained with shortcut keys. I am feeling that in near future it turns me out as a cool developer. Bundle
    thanks, Dave Gray!🤩🤩

  • @MohammadBarghamadii
    @MohammadBarghamadii 2 роки тому +1

    Hi Dave, I don't know how to thank you. Thank you so much for your great tutorials.

  • @rezamahmoudi4668
    @rezamahmoudi4668 Рік тому

    One request: can you repeat the development in the above part, with the useReducer?

  • @notusedbrain
    @notusedbrain 3 роки тому +2

    Hey Dave,
    I am following your tutorial and was confused with onDoubleClick event listener as it wasn't needed in my case. The only difference in my code is that I had to use htmlFor attribute for a label as otherwise I was getting an error.
    I installed eslint following some tutorial online and airbnb styleguide but that has many unexpected quirks, especially when following tutorials.
    Would be great to see a video about your working environment setup and yes I already watched your top 5 VS Code extensions for beginners.
    Great content and I love how you keep mentioning useful shortcuts when working with the code editor as it extremely helpful.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  3 роки тому +1

      Thanks for the notes! My working VS Code setup is pretty much what you see in the tutorials. I know some that add a lot to theirs, but I keep it very plain. The bracket pair colorizer 2 extension does help me and I usually keep prettier running, too.

    • @notusedbrain
      @notusedbrain 3 роки тому

      Thank you. I was wondering if you used any linting rules // style-guides but I guess is the best to keep things simple at the beginning as my example shows.
      Often you mention keyboard shortcuts but I might have missed how do you change multiple items at the same time Ctrl + D?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  3 роки тому +1

      @@notusedbrain you are right - Ctrl + D will select multiple instances and let you edit them all at once.

  • @ahmad-murery
    @ahmad-murery 3 роки тому

    I read that keys are needed for react to detect the changes (add, update and delete) in a list but I know it worked for me without them and I was wrong,
    I just discovered that react will use list indexes for keys if not explicitly assigned which explain why id did work for me.
    With all my current workload, I feel like I still need to do my homework as a student,
    Thanks Dave,

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  3 роки тому +1

      Good note Ahmad. Yes, index should be available. Without explicit assignment of keys, I believe an error will show in the console while the JSX may still render. 🤔😃

  • @caffeinated-pixels
    @caffeinated-pixels 3 роки тому

    I'm watching this series as a nice React refresher and to pick up some tips. Didn't know about React Icons, so thanks for that!

  • @jamshidtashkent1976
    @jamshidtashkent1976 2 роки тому

    I'm so happy to find your channel. Your videoes are very useful. Thank you so much.

  • @agroforestryconsultancyroz3157
    @agroforestryconsultancyroz3157 3 роки тому

    As a react beginner I can tell this a very important video

  • @prasannapm3220
    @prasannapm3220 Рік тому

    Thank you Dave!

  • @ghostpieces2362
    @ghostpieces2362 3 роки тому +1

    Can you explain why we need to spread ...item in Line 24. I understand items.map loops through items and stores the object into item. We then check if item.id === id that was passed in. If True we need to spread item. This is where i'm confused. Couldn't we just say ? !item.check: item)'. Thanks

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  3 роки тому +2

      Hi Steven, I'm going by memory as I have many videos, but you can provide a timestamp with your questions if you want to provide a specific reference. When you update the state of an object, you need to spread in all the properties. If you do not, you will erase them all. I go into detail with examples about this at the 10 minute mark of this video: ua-cam.com/video/yvTGXH7uybA/v-deo.html

  • @mohajeramir
    @mohajeramir 2 роки тому

    I am rooting for you to reach the 100k milestone 💯

  • @harag9
    @harag9 Рік тому

    New to your channel, and just subbed. Great tutorial series, many thanks. I come from a old school html/JS/Jquery background - it really does look weird when I see "html like" (JSX) code within javascript. So far it seems more disorganised to me.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Рік тому +1

      I understand. I think you'll get used to it. Same happened to me!

  • @GorritoCodes
    @GorritoCodes 9 місяців тому

    why yours .map works without a return statement, but mine doesn't?
    Thank you again!

  • @vigneshvicky113
    @vigneshvicky113 Рік тому

    Please explain handlecheck conditon

  • @Retrohertz
    @Retrohertz 3 роки тому

    11:40 - I've been developing HTML for a few years and it's only now I've come across tabIndex is. I'm assuming that keeping it at '0' means that the browser determines the tab order as opposed to the developer. Is that right?
    If you were going to set a tab index order, I suppose we could do so by using the curly braces and adding a reference to the index 'i' argument in the .map function. Is it a bad idea to set a tab order?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  3 роки тому +1

      Good questions! The assumption about how tabindex works is not quite accurate. A tabindex of 0 puts the element in the sequential tab order. More on tabindex here: developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex Thanks for the note! 💯

    • @Retrohertz
      @Retrohertz 3 роки тому

      @@DaveGrayTeachesCode Thanks. That makes sense.

    • @djheckler92
      @djheckler92 3 роки тому

      ​@@DaveGrayTeachesCode Is the reason you decided to add tabindex to the trashcans to improve accessibility for keyboard users? Thanks

  • @vigneshvicky113
    @vigneshvicky113 Рік тому

    Please explain handlecheck condition

  • @bnmbnm7278
    @bnmbnm7278 2 роки тому

    Excuse me, 20:23
    Q1:I can't understand what meaning is? { ...item, checked: !item.checked }
    I understand { ...item} or {checked: !item.checked }, but { ...item, checked: !item.checked }, I can't understand, can you explain it?
    Q2:Why use ...item? I know it is spread syntax.. but I can't understand why "...item" is work in the Ternary Operator?
    I've been thinking about it for a long time.
    (I have seen map(), Spread_syntax and Ternary Operator in MDN)

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +7

      If my memory is correct you are working with todo list items here. The object is one item. An item has multiple properties. When you see the spread operator here, we are spreading in the properties of the item to create a new object. The comma is added in order to add one more property to the object. If we add a property that already exists like the property checked, then the new property checked will overwrite the previous one. So in the example you are asking about, we spread in the properties including the existing checked property, but then we overwrite the checked property with the opposite value (true or false).

    • @jiweihe3413
      @jiweihe3413 2 роки тому

      @@DaveGrayTeachesCode thanks for the clear explanation! I had the question

  • @ioniangaming
    @ioniangaming 7 місяців тому

    Thanks Professor

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

    could you explain why style={(item.checked) ? { textDecoration: 'line-through' } : null} updates the html without having to issue a re rendering of the page?

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

      I think I understand now. Clicking the checkbox issues a state change which triggers a re-render of the component. The value of the linethrough style is based on the new state that triggered the re-render

  • @fkbey5756
    @fkbey5756 2 роки тому

    Thank you for great tutorial.
    i change the status with a for loop.
    i want to know, is Maps performance is better then for loop? thank you.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +1

      You're welcome! I prefer map. I haven't looked into the performance. I'm guessing if there is a difference, it would be very small.

  • @huyphamfc
    @huyphamfc Рік тому

    What is your icon theme?

  • @oncoding4520
    @oncoding4520 2 роки тому

    Love your work

  • @ЕвгенийКарышев-я1я

    thanks Dave

  • @Gintoki_Madao
    @Gintoki_Madao 2 роки тому

    Commenting for the algorithm

  • @immortalaigs4203
    @immortalaigs4203 2 роки тому

    Thank you Sir!

  • @hanszoll4943
    @hanszoll4943 2 роки тому

    Thank you

  • @1conscience0dimension
    @1conscience0dimension Рік тому

    npm i -D is same as save dep not save

  • @TruthSeeker23-m4o
    @TruthSeeker23-m4o 2 роки тому

    const handleCheck = (id) => {
    const listItems = items.map((item) => item.id === id ? { ...item, checked: !item.checked } : item);
    setItems(listItems);
    above code is totally confusing for me why to ...item spread items could you explain in a bit laymen term????

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +2

      Hi Lavesh. When you first spread in item, it has all of the object properties. You follow it with a comma and then provide the checked property to overwrite the previous checked value. It is a true/false, yes/no type of value so when we say !item.checked, it sets it to the opposite of what it was before.

    • @TruthSeeker23-m4o
      @TruthSeeker23-m4o 2 роки тому

      @@DaveGrayTeachesCode thanks dave got it. :)

  • @aya2222
    @aya2222 2 роки тому +2

    why is it parentheses() instead of curly bracket{} after arrow ?
    {items.map((item) => ( //why is it not curly bracket?


    {item.item}
    Delete

    ))}

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +1

      That's a good question, and I realize it is different from what you typically see in Javascript functions. Parenthesis group multiple lines of code in a return. In your example, I used map() which is a higher order function. It returns values and the value being returned in this example is on several lines of code. I hope that helps!

    • @aya2222
      @aya2222 2 роки тому

      @@DaveGrayTeachesCode Thank you for your explanation!!

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому

      @@aya2222 you're welcome! 🙏

  • @dawid6026
    @dawid6026 Рік тому

    7:17

  • @AbdulRazzaq-jy5qx
    @AbdulRazzaq-jy5qx 2 роки тому

    Loved your teaching style. Just Amazing

  • @CodingBandit
    @CodingBandit 2 роки тому

    welp now this is when it starts getting hard

  • @vigneshvicky113
    @vigneshvicky113 Рік тому

    I totally confused in this video

  • @TravinskiyVladislav
    @TravinskiyVladislav 2 роки тому

    Top

  • @oussamabouallati
    @oussamabouallati 2 роки тому

    Thank you sir!