ReactJS – How to add key prop to the Element transmitted as Object in React

Approximately the code looks like this (CoffeeScript)

//In Parent component

render: () ->

mycomp =




//In Child component

render: () ->

someContent = [passedComp, ]



{someContent}

This will generate a warning in the Child component about missing keys in the array.

The question is how to add key={1} to the passComp in the Child component. I can’t do this in the Parent’s render method (with some_prop) because I don’t yet know what the key should be. I need to Add the key prop to the Child component-but what is passed here is already an object.

How to modify passComp to obtain the key?

>Update:

I have

someContent = [{passedComp}, ]

It got rid of the React warning, but the extra span broke my (reaction-bootstrap) CSS. Is there a better solution?

If the component is already instantiated, the only way to do this is to clone your component and add a secret Key attribute

About the code looks like this (CoffeeScript)

//In Parent component

render: () ->

mycomp =




//In Child component

render: () ->

someContent = [passedComp, ]



{someContent}

This will generate a warning in the Child component about missing keys in the array.

p>

The question is how to add key={1} to the passComp in the Child component. I can’t do this in the parent’s render method (with some_prop) because I don’t know what the key should be now. I Need to add the key prop in the Child component-but what is passed here is already an object.

How to modify passComp to obtain the key?

>Update:

I have

someContent = [{passedComp}, ]

It got rid of the React warning, but the extra span broke my (reaction-bootstrap) CSS. Is there a better solution?

If the component is already instantiated, the only way to do this is to clone your component and add the key attribute

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5953 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.