+ 4

{Solved} React with unique key props issue

I have just created a React app, it can generate result as I expected. However the React gives an warning of unique key props are needed for all the iterators. The warning persists, even though I have added all the key props wherever there is map function iteration. Did I miss something? https://code.sololearn.com/WjbVk37DHbgM/?ref=app PS. The code was originally created by Gordon, I modified it to work with React functions for testing React Hooks features.

27th Feb 2019, 10:05 AM
Calviղ
Calviղ - avatar
7 odpowiedzi
+ 17
Calviղ the key on Course (line 130) is on the inner element The key should be on the wrapping div element
27th Feb 2019, 11:17 AM
Burey
Burey - avatar
+ 5
I saw the keys are all literal templates and supposed to include an index number in naming the keys. So, I make a slight edit: https://code.sololearn.com/WHm5XCQs0VZe/?ref=app I tried to display the innerHTML to see which key are repeated. The result is not very satisfactory. Because it seems that the keys attributes are not kept after rendering. If there is a way to console log the keys once they are made. We may be able to at least identify our target to debug.
27th Feb 2019, 10:47 AM
Gordon
Gordon - avatar
+ 3
Ohh.. Now I see the issue, thank you Burey. The code should be const Courses = ({courseItems}) => ( <div> { courseItems.map((c,i) => <Course key={'course'+i} courseItem={c} />)} </div> );
27th Feb 2019, 11:40 AM
Calviղ
Calviղ - avatar
+ 2
Gordon thanks for showing the code from the app element, didn't aware it could be checked in this way. 👍
27th Feb 2019, 11:42 AM
Calviղ
Calviղ - avatar
+ 2
For information only, Original source was coded by Gordon with vallina JavaScript. https://code.sololearn.com/WW7fwgNfS2jP/?ref=app
27th Feb 2019, 11:49 AM
Calviղ
Calviղ - avatar
0
Const course=({courseItems})=>(<div>
28th Feb 2019, 10:59 PM
ras
0
could i make a code that would tell my HP notebook which programs do i need to reinstall so that i can get wi-fi if anybody knows please tell me
2nd Mar 2019, 3:12 AM
Karmit Nostaw
Karmit Nostaw - avatar