Тёмный

ReactJS Tutorial - 19 - Index as Key Anti-pattern 

Codevolution
Подписаться 645 тыс.
Просмотров 313 тыс.
50% 1

📘 Courses - learn.codevolution.dev/
💖 Support UPI - support.codevolution.dev/
💖 Support PayPal - www.paypal.me/Codevolution
💾 Github - github.com/gopinav
📱 Follow Codevolution
+ Twitter - / codevolutionweb
+ Facebook - / codevolutionweb
📫 Business - codevolution.business@gmail.com
codepen.io/gopinav/pen/gQpepq

Опубликовано:

 

9 дек 2018

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 100   
@tiagobordin6580
@tiagobordin6580 Месяц назад
Showing what not to do is as important as showing what to do. You are an absolute legend.
@ahjiba
@ahjiba 3 года назад
For those who are still confused see the below example You have abcd array of letters which map to 0123 indices -> react shows us key0 a, key1 b, key2 c, etc You take out the second letter (b) through the array, acd which maps to 012. React shows key0 a, key1 c, key2 d What we wanted to see is key0 a, key2c, key3 d
@cecilliongaming49
@cecilliongaming49 3 месяца назад
Got it , thanks !
@sdaiwepm
@sdaiwepm 8 месяцев назад
Thank you for speaking slowly and clearly so that we can follow every word!
@Prashant912
@Prashant912 5 лет назад
eagerly waiting for new videos :) you are just a coding superstar. Your videos are really helping me a lot in my career right now. Totally dependent on your videos.
@toannew
@toannew 3 года назад
1:55 case: we do not have ID to make keys for a list 3:52 pass index as keys 6:00 issue scenario with index 7:00 -9:05 index as key anti-pattern 9:20 when to use the index as keys 10:10 solution
@nouru6856
@nouru6856 3 года назад
I literally solved a big issue I had. Thanks to this vid.
@IAMTHEMUSK
@IAMTHEMUSK 4 года назад
You are my new favorite youtuber. I even spend my evenings listening to you 🤣
@hitanshimehta430
@hitanshimehta430 4 года назад
Thank you so much for making the video!! you are helping across the world! Thanks again!
@Pradeep-eq4ue
@Pradeep-eq4ue 5 лет назад
Very nice explanation. Waiting for other topics. Please do some on redux and react router also. awesome work👍👍.
@leangsengkao4753
@leangsengkao4753 4 года назад
Thank you so much for sharing. I'm really appreciated your tutorial.
@rameshbuvi3384
@rameshbuvi3384 4 года назад
Your teaching is the best bro, when compare with other tutorials...Thanks Bro
@nikolavladimirov1254
@nikolavladimirov1254 3 года назад
Thanks man. Your videos and your way of explaining very cool.
@ucngoctran4634
@ucngoctran4634 3 года назад
best explanation for me. Thank you so much!
@huanshao2165
@huanshao2165 4 года назад
Vishwas, you are the best reactjs teacher!
@igorswies5913
@igorswies5913 3 года назад
thank you now I understand that you can use index as key as long as the elements of the array don't move
@arielspalter7425
@arielspalter7425 4 года назад
Awesome tutorial , thank you!
@abhitripathi
@abhitripathi Год назад
Wow, You explained it so well, Thank You!
@sarazamani4914
@sarazamani4914 3 года назад
Great tutorial,best explanation,thank you
@gousmanyari7067
@gousmanyari7067 4 года назад
Nice Explanation Sir...I love Your Video...
@lathagm666
@lathagm666 8 месяцев назад
completed video 19. Thanks 🙂
@mirzafaisalbaigfaisal6324
@mirzafaisalbaigfaisal6324 Год назад
just amazing course!! Why didnt i found thiscourse early.🤦‍♂🤦‍♂
@jagdishshetty4782
@jagdishshetty4782 5 лет назад
Great tutorial !!! Thx !!!
@govindsharma3636
@govindsharma3636 9 месяцев назад
🗝 The "key" prop in React is essential for rendering lists efficiently. It should have a unique value within the list. 🗝 The "key" prop value can be any unique identifier within the list, such as ID or name, but it should not be accessed or used in child components. 🔄 React uses keys to efficiently update the UI when items are added, removed, or changed within a list. 🗝 If your data doesn't have a unique identifier, you can use index as the key, but it's less efficient and should be a last resort.
@shineLouisShine
@shineLouisShine Год назад
Thank you. You are a true champ indeed.
@ssp8674
@ssp8674 4 года назад
Great tutorial, I Love you ~~
@poojakamble3643
@poojakamble3643 4 года назад
only because if you i have managed to crack my React js interview thanks a ton looking forward for more videos on react native
@agamurat3019
@agamurat3019 4 года назад
so what was the result? have u passed successfully
@ujwalc9226
@ujwalc9226 3 года назад
@@agamurat3019 yes , cuz she said she "cracked" it😁
@nadicadizdarevic2835
@nadicadizdarevic2835 2 года назад
😃GREAT !!!!
@brunagobi7393
@brunagobi7393 3 года назад
the best course ever
@mohammadalisakib6565
@mohammadalisakib6565 3 года назад
Thank you once again!
@vaibsify
@vaibsify 2 года назад
awesome explanation 🙏
@EngineerNick
@EngineerNick 3 года назад
Thankyou for the video :)
@asifurrahman5436
@asifurrahman5436 3 года назад
Awesome explanation. BTW you guys can use shortid npm package for unique id.
@syedfaheem1185
@syedfaheem1185 Год назад
Thank you so much.
@AAKSHAS
@AAKSHAS 2 года назад
2:44 arrow function was passed to map method, then arrow function receives a 2nd param which is the index of the element in current iteration.
@hasanmirarabshahi1956
@hasanmirarabshahi1956 2 года назад
good explanation, thanks
@Aditya.Santra
@Aditya.Santra 2 года назад
Very Helpful Video
@elchino7672
@elchino7672 3 года назад
Wonderful! Wonderful! Wonderful!
@SemenAlexndrovich
@SemenAlexndrovich 2 года назад
Thanks dude!
@AxxionMarketPlace-iu6ri
@AxxionMarketPlace-iu6ri 11 месяцев назад
Thank you
@saber__tooth5256
@saber__tooth5256 4 месяца назад
Thank you.
@ajaybatham3622
@ajaybatham3622 4 года назад
thankyou sir....
@sahilkashyap8756
@sahilkashyap8756 3 года назад
What is the use of three periods before todo and before the array of list while adding new element
@wardenpataski2882
@wardenpataski2882 3 года назад
Can I just map a new array list and insert an id value for each object in the list? Sorry if it's a dumb question I'm just a beginner.
@harshvardhansingh780
@harshvardhansingh780 2 года назад
Thankyou sir
@siddharthabajpai4182
@siddharthabajpai4182 3 года назад
3:02 made me smile....ye bhi karr sakte😀😀
@Collateral147
@Collateral147 3 года назад
Why do the id and timestamp values still maintain the correct placement? - what links them that doesn't link the inputted value
@mzeeshan
@mzeeshan 3 года назад
Loved your way of teaching. Would you be kind enough to mention which extension you are using to uncollapse the code with plus (+) sign (like a region/section in C#) at 0:51 please?
@jyotiprakashnayak942
@jyotiprakashnayak942 2 года назад
Tap on the line no you have to squeeze on the no bar
@umutbarskorkut7383
@umutbarskorkut7383 4 года назад
Hello Vishwas. I love the way you teach very clearly! Thanks for the videos. Can we use hash of the list element as a key?
@AAKSHAS
@AAKSHAS 2 года назад
7:00 index as key anti-pattern
@siddhartharock7584
@siddhartharock7584 9 месяцев назад
Hi sir. In this case, I can understand Key is not changed. But will that be an issue as 'Key' prop is used by React alone right and anyways we will not able to use that prop and hence do we still need to worry on it? Can we use index as key till we are not rely on key property for anything? Please advise. Thanks in advance.
@prathameshjadhav7889
@prathameshjadhav7889 4 года назад
I create table from static array in reactjs . table contains {id,name, and address} fields. Name is clickable now but how i can get row data when i click on name. plz make video for it
@laxmanmishrabbk
@laxmanmishrabbk 4 года назад
sorry discussing other topic, your video index is wrong after 17 missing 18 and after 25 it is showing 19.
@abhinandankhilari9729
@abhinandankhilari9729 4 года назад
I got a question. You said that if no key is passed, then default key is passed as index. In the previous lecture (no. 18), when no key is passed, then default key would be passed as index accordingly. There you mentioned that adding an item at the start of the list will result into performance issue but not any unexpected behaviour in the list rendering. In this video, you are mentioning that adding an item at the start of the list will result into unexpected behaviour. Why this contradiction?
@tulsikhatri8694
@tulsikhatri8694 4 года назад
May be it is just for the explanation, that why not to use index as key...
@narendrakanneti2966
@narendrakanneti2966 5 лет назад
Waiting for .. Next... episodes..
@kamarajugaddamanjula1261
@kamarajugaddamanjula1261 3 года назад
hi i am learning sir
@sudhirme101
@sudhirme101 Год назад
but , what is the solution if we using index as key and list will need to be sorted ?
@BrantK147
@BrantK147 Месяц назад
Oh ok, so the key prop goes in the JSX tag, only if the JSX is in the parent component. Got it :)
@chillchill0409
@chillchill0409 Год назад
7:03 that is incorrect explaination for the codepen, react doc mentions the component state in the uncontrolled input is the reason. Without that state, the element will add to the top just fine with index as key, it only causes more updating to the DOM node
@yaunghein3395
@yaunghein3395 3 года назад
What if the supported array doesn't have an unique ones(id or something), and we also need to filter or order that array too?
@jyotiprakashnayak942
@jyotiprakashnayak942 2 года назад
Use filter()
@AhamedKabeer-wn1jb
@AhamedKabeer-wn1jb 3 года назад
Thanks..
@in2techs3
@in2techs3 2 года назад
did not understand why dorting doesnot sort actual values but index
@ibrahemkhalil5924
@ibrahemkhalil5924 2 года назад
Bruce Wayne, Clark Kent, Diana Prince ?
@yatingupta1426
@yatingupta1426 3 года назад
If you use controlled component with this anti pattern, then this issue will not come. It only comes when you use uncontrolled component(here input text field) with this anti-pattern.
@dennyh66
@dennyh66 3 года назад
But it’s will cause extra renders, still not good
@manfree503
@manfree503 7 месяцев назад
Why weren't Index, ID, and Created at not get messed up too like Item ? I thought they were all part of ToDo?
@manfree503
@manfree503 7 месяцев назад
Ah.. because Index, ID, and Created at receive data from props, which is received by the list which is itself ordered properly. But Item is , which is not something from the list.
@aanya4818
@aanya4818 3 года назад
4:54 Requesting more explanation for better understanding
@prisinha
@prisinha 2 года назад
3:00 second param of map function
@het314
@het314 3 года назад
What's the purpose of such behavior?
@swapnilchaudhari857
@swapnilchaudhari857 5 лет назад
what if dont pass key. That time what value it will take as a key.
@undentifiedkc
@undentifiedkc 5 лет назад
i think he just mention if no key is pass, then by default index is used as key @ 10:35
@simple8810
@simple8810 3 года назад
@@undentifiedkc yes you are right
@Wakkyguy
@Wakkyguy 3 года назад
If I remove the input box and replace it with a span with id as text, then I cannot simulate this behavior. Guess it only happens when you have an uncontrolled component in ur siblings.
@vishallohbande5811
@vishallohbande5811 Год назад
Actually i am the begginer of react and i want know how you implement the project of in this video
@akashnag3879
@akashnag3879 5 лет назад
any answer to such issue??
@yashmahalwal
@yashmahalwal 5 лет назад
An alternative is generating a unique key for each item of the list (uuid) and then use that as key
@FANSasFRIENDS
@FANSasFRIENDS 2 года назад
Making a calculator, Just realized how important this video is😅
@kek-li4il
@kek-li4il 10 месяцев назад
the odin project
@mrrishiraj88
@mrrishiraj88 2 года назад
👍
@technerd900
@technerd900 Год назад
6:50 * this is the problem of using the index as key * ;)
@mohammadhajeer3649
@mohammadhajeer3649 Год назад
As prophet Muhammad (PBUH) said those who don't thanks people don't thank God, really thank you for such a wonderful course.👍🌼
@kamarajugaddamanjula1261
@kamarajugaddamanjula1261 3 года назад
hi sir
@bhubeshsr6281
@bhubeshsr6281 3 года назад
Too musch of Ads , How much u earned from this tutorial , must more than a billion !!!
@vigneshgvs
@vigneshgvs 2 года назад
key prop for normal arrays - can be its 'index'. But it has disadvantages. so don't use use index.
@szeredaiakos
@szeredaiakos 3 года назад
Why would it be an anti-pattern? Me and mi teammates know full well how keys behaves.
@szekri1001
@szekri1001 4 года назад
So basically you can use index as a key if your list is an ENUM
@mohamedyunus8172
@mohamedyunus8172 4 года назад
A simple way of creating a unique key is to use Math.random() Instead of using one of the npm packages that generate a unique ID for the list const nameList = names.map(name => {name})
@marktoth6334
@marktoth6334 4 года назад
I don't think this is true. When rendering Math.random would return a new value each time the map function was run. So your key while being unique would no be static. It would change each time resulting in React mutating the entire list instead of inserting. The key MUST BE immutable.
@TheGryphon14
@TheGryphon14 3 года назад
don't do this..
@sahilkashyap8756
@sahilkashyap8756 3 года назад
Instead of assigning math.random() to keys assign it to the id of list
@vscodeaddict6607
@vscodeaddict6607 Год назад
man u confused me in last video and this one also. how i will pass index to Persons u skiped that part. 😕😕😠
@sajibdas8934
@sajibdas8934 Год назад
You confused me
@guilhermerosa7583
@guilhermerosa7583 2 года назад
for me it´s too hard to understand the indian accent
@dansmar_2414
@dansmar_2414 2 года назад
His accent is super fine. Very clear for me. He talks slowly and paused. One of the best I've seen until now
Далее
ReactJS Tutorial - 20 - Styling and CSS Basics
11:40
Просмотров 500 тыс.
Why do We Need Keys in React?
7:47
Просмотров 10 тыс.
ReactJS Tutorial - 21 - Basics of Form Handling
13:49
Просмотров 592 тыс.
React index as key | Don't use index as a key
5:27
Просмотров 3,3 тыс.
10 Design Patterns Explained in 10 Minutes
11:04
Просмотров 2,2 млн
ReactJS Tutorial - 18 - Lists and Keys
7:32
Просмотров 382 тыс.
ReactJS Tutorial - 17 - List Rendering
11:57
Просмотров 521 тыс.
Why you should NEVER use index as key in React Lists
19:28
Most Senior React Devs Don’t Know How To Fix This
9:25