简体   繁体   English

修复警告 ///列表中的每个孩子都应该有一个唯一的“键”道具

[英]fixing warning ///Each child in a list should have a unique "key" prop

i am having the same issue here in the below code.我在下面的代码中遇到了同样的问题。 I have added a key where think it is appropriete but still getting key warning message.我在认为合适的地方添加了一个键,但仍然收到关键警告消息。 Hi guys, i am having the same issue here in the below code.大家好,我在下面的代码中遇到了同样的问题。 I have added a key where think it is appropriete but still getting key warning message.我在认为合适的地方添加了一个键,但仍然收到关键警告消息。

Can you help, please?你能帮忙吗?
Leo狮子座

import { useState } from "react";
import { FaTimes } from "react-icons/fa";
import EditSkillsForm from "./editSkillsForm";
const SkillsList = ({ inputs, handleDeleteClick, handleCancelClick, handleEditClick, setIsEditing, handleUpdateInput,currentInput}) => {
const [ isEditing, setISEditing ] = useState(false);
  //const [ currentSkill, setCurrentSkill ] = useState({});

 handleEditClick = () =>  {
     setISEditing(true);
     console.log("editing", true)

  }
  

  


  return (

    <div className="col-lg-4 col-sm-6 mb-4">
      <div className="card p-2">
        <div className="card-Header text-center mb-4">
          <h4 className="card-title mt-2">Mastered Skills List</h4>
        </div>

        {inputs.map((skill, idx) => {
          return (
            <>
              <div className="card width: 10rem; mb-3 p-2" key={idx}>
                <div className="card-header text-center mb-4">
                  <h5 className="card-title mt-2">{skill}</h5>
                </div>
                <img src="../../logo.svg" className="card-img-top" alt="..." key={idx} />
                <div className="card-body">
                  <div className="card-title text-center mt-2 " key={idx}>
                    {
                      isEditing ? (
                        <div key={idx}>
                        <EditSkillsForm 
                        inputs={inputs} 
                        editing={setIsEditing} 
                        cancelClick= {handleCancelClick}
                        updateInput = {handleUpdateInput}
                        currentInput={currentInput}
                              
                         />
                        </div>
                      ) : null
                    }
                    {/* <EditSkillsForm inputs={inputs} /> */}
                    <ol key={idx}>
                      Skill name: {skill}
                    </ol>
                  </div>
                </div>
                <div className="card-footer" >
                  <div className="row mb-2" key={idx}>
                  <button
                    className="btn btn-primary w-100"
                    onClick={() => handleEditClick(inputs.idx)}>Edit
                  </button>
                  </div>
                  <div className="row">
                  <FaTimes className="mb-2" fill="#ffc800" onClick={() => handleDeleteClick(idx)} key={idx} />
                  </div>
                </div>
              </div>
            </>
          )
        }
        )}
      </div>
    </div>
  );
}

export default SkillsList;

the key must be unique for all the elements in your component.对于组件中的所有元素,键必须是唯一的。 as I can see you using the same key idx in multiple div elements so it isnt unique anymore.我可以看到您在多个 div 元素中使用相同的键idx ,因此它不再是唯一的。 try to make for each div a special name in addition of that idx value to make it unique for each one.除了idx值之外,尝试为每个 div 指定一个特殊名称,以使其对每个 div 都是唯一的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 像这样的警告:列表中的每个孩子都应该有一个唯一的“关键”道具 - warning like : Each child in a list should have a unique "key" prop 反应警告:列表中的每个孩子都应该有一个唯一的“关键”道具 - React Warning: Each child in a list should have a unique "key" prop 警告:列表中的每个孩子都应该有一个唯一的“key”道具 - Warning: Each child in a list should have a unique “key” prop 错误:警告:列表中的每个孩子都应该有一个唯一的“关键”道具 - ERR : Warning: Each child in a list should have a unique "key" prop Reactjs:警告列表中的每个孩子都应该有一个唯一的“关键”道具 - Reactjs: Warning Each child in a list should have a unique "key" prop 警告:列表中的每个孩子都应该有一个唯一的“键”道具来切换 - Warning: Each child in a list should have a unique "key" prop for switch 警告列表中的每个孩子都应该有一个唯一的“关键”道具 - Warning Each child in a list should have a unique "key" prop 添加了关键道具 || 警告:列表中的每个孩子都应该有一个唯一的“key”道具 - Added key prop || Warning: Each child in a list should have a unique "key" prop 警告:列表中的每个孩子都应该有一个唯一的“key”道具,即使它有唯一的 key React - Warning: Each child in a list should have a unique “key” prop even tho it has unique key React 反应警告:列表中的每个孩子都应该有一个唯一的“钥匙”道具,当钥匙被提供并且是唯一的 - React Warning: Each child in a list should have a unique "key" prop when key is provided and unique
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM