This is why you need the key property in React

This is why you need the key property in React

Web Dev Cody

1 год назад

17,024 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Jonathan Buso
Jonathan Buso - 06.09.2023 09:19

I conceptually understand why the key prop is important. I can't replicate it in my own app properly though. In a more complex application where let's say we are mapping through an array of objects. Where do we put the key prop when there are multiple properties to use within the mapping? i.e. Product Card with product.title, product.description, etc

Ответить
pujan parikh
pujan parikh - 18.05.2023 14:34

so simply explained, not sure why we don't see such a lucid example elsewhere. thank you so much!

Ответить
OH NO
OH NO - 11.01.2023 23:11

I had a doubt. If I assume that I have 2 li elements from my array and now I add one more say by a button click, and the addition happens at the end of the array, will react understand that a new addition was made and not re render the entire list?

Ответить
Mohamed Yamani
Mohamed Yamani - 03.11.2022 11:57

Great example!

Ответить
Võ Phát
Võ Phát - 20.09.2022 13:55

What name color theme vscode

Ответить
Wassa L
Wassa L - 17.09.2022 10:23

You can also let React assigning the keys by using: React.Children.toArray(numbers.map(() => <Component />)

Ответить
Dan Gill
Dan Gill - 16.09.2022 15:14

Seriously great content. Keep doing what you’re doing! Great job!

Ответить
Waldemar Peralta
Waldemar Peralta - 16.09.2022 10:00

Hi! Since you mentioned eslint, I wanted to ask: on your proyects, do you use eslint for enforcing rules AND formatting, or do you use prettier for formatting and eslint only for the rules? I looked this up, but it seems like every single article has a different way to set it up, or a different opinion. Have you made a video about this before?

Ответить
Shaye
Shaye - 16.09.2022 09:46

I have no clue what your talking about and I’m gonna go into computer science degree. Should I worry?

Ответить
Bastian Ebiko Jesuiter
Bastian Ebiko Jesuiter - 16.09.2022 08:48

And then react is complaining about not having keys for fragments...
And I ask myself why, when it removes fragments anyway.

Ответить
ThatGuyYouSaw
ThatGuyYouSaw - 16.09.2022 07:48

You mentioned not using index, but never mentioned why. Is there a reason why we shouldn't use that?

Ответить
Pesterenan
Pesterenan - 16.09.2022 01:46

That was a great way of showing whi this is important! Thanks for the video!

Ответить
SeinVater
SeinVater - 15.09.2022 20:23

Good example right there. Still in some cases you don't have any specific id, especially if you have some items inside items, I still remember in my 2 months intern that I was supposed to write 3 purchase offers (3 Kind of services) width 20 features they provide. I just used the index as key after my boss was wondering what these generated ids are. If you google these stuffs some people just not see it as optimal way to generate these keys, but you also can't just use the index 🥴. I hated the css part in my internship, just wasted so much time with css. But I still learn more about React and TS. Glad that I was able to write code, some people in my class had done nothing in their intern, nothing worse than doing nonsense and waste potential. A teacher just asked me if I'm interested to work in his Startup, great experience.

Ответить
Voided Name
Voided Name - 15.09.2022 20:12

^^ the reason I prepended the numbers in my demo was due to render order and state association. As I stated in my video, since it matches them by render order, we want to add the items out of order. If we add them in order the new item will be at the end, but that's also a new spot in the render sequence => it gets a new state, everything before will be matched to the same state and we won't see this bug, even though it is happening. Glad my demo was helpful to you.

Ответить
Marjan Lukavyi
Marjan Lukavyi - 15.09.2022 20:00

what is the plugin for displaying errors near the code?

Ответить
Feiertag
Feiertag - 15.09.2022 18:41

Off topic question, do you plan on a video series on react testing library?

Ответить
Naresh E
Naresh E - 15.09.2022 17:45

what is the extension name you are using for error finder?

Ответить
Rathod Sandeep
Rathod Sandeep - 15.09.2022 17:21

When it come to quality content this guy never dis

Ответить
Willy Horizont
Willy Horizont - 15.09.2022 16:58

What is that in the cursor? Is that chrome extension or software? Whats that name?

Ответить
dog4ik
dog4ik - 15.09.2022 16:48

Everyone is talking about how bad is this but nobody explains why! Thanks!

Ответить
Zach Burhans
Zach Burhans - 15.09.2022 16:41

I still catch this during peer reviews. Thanks for talking about this!

Off topic question, do you plan on a video series on react-router 6.4? The implications for useRouteLoaderData has me beyond excited

Ответить
Tina Seibert
Tina Seibert - 15.09.2022 16:35

Good job babe

Ответить
Theofanis Birmpilis
Theofanis Birmpilis - 15.09.2022 16:15

Are u considering creating any udemy courses on React? Do you have any course recommendations for someone who knows the basics of React but wants to get to the next level?

Ответить
Desire Chiduku
Desire Chiduku - 15.09.2022 16:14

Love this one ☝️

Ответить
Dion Tu
Dion Tu - 15.09.2022 16:13

Cool example for showing the reason behind using the key property. Love the content!

Ответить