-1

code is here

   <React.Fragment>
    <div className="js-container">
      <div className="js-sidecontent">
        {[{ title: "Js, values: ["s1", "s2"]}].map((f_list) => (
          <div className="js-sidecontent-container" key={f_list.title}>
            <button className="feature-title">{f_list.title}</button>
            {f_list.values.map((f_list_value) => (
              <button className="feature-title-list">{f_list_value}</button>
            ))}
          </div>
        ))}
      </div>
    </div>
  </React.Fragment>

I have the above code within the render method of React Component and I have the key-value as the property of parent div element. still, I am getting below Error in Console.

Warning: Each child in a list should have a unique "key" prop.

How it can be solved?

Emile Bergeron
  • 17,074
  • 5
  • 83
  • 129

2 Answers2

3

You need to specify a key for the button too:

{f_list.values.map((f_list_value, idx) => (
    <button className="feature-title-list" key={idx}>{f_list_value}</button>
))}
devcrp
  • 1,323
  • 7
  • 17
0

you can fix with code like this:

{f_list.values.map((f_list_value, index) => (
   <button className="feature-title-list" key={index}>{f_list_value}</button>
))}

If you render a list of element you have to add an extra attribute key. This attribute identifies uniquely your elements.

Stoic Lion
  • 470
  • 2
  • 14