简体   繁体   English

列表中的每个孩子都应该有一个独特的“关键”道具。 但我没有调用任何组件

[英]Each child in a list should have a unique "key" prop. but i'm not calling any component

if i call all discount price using map method.如果我使用 map 方法调用所有折扣价。 it perfectly work but i see in console and like this error are found.它完美地工作,但我在控制台中看到并且发现了这个错误。 how to fix it如何修复它

 <div className="priceCal flex flex-col items-center">
       <p style={{ fontSize: '1.5em' }} className='font-medium pt-3'>Total items: </p>
          {
            data.map((v, i)=>{
            return <p className='font-bold text-xl'>Rs. {v.DiscountPrice}</p>
             })
         }
</div>

Click to view the error点击查看错误

react-jsx-dev-runtime.development.js:117 Warning: Each child in a list should have a unique "key" prop.

Check the render method of `Cart`. See https://reactjs.org/link/warning-keys for more information.
    at p
    at Cart (http://localhost:3000/static/js/bundle.js:3393:74)
    at Routes (http://localhost:3000/static/js/bundle.js:63733:5)
    at RouterMenu
    at App (http://localhost:3000/static/js/bundle.js:140:81)
    at Router (http://localhost:3000/static/js/bundle.js:63666:15)
    at BrowserRouter (http://localhost:3000/static/js/bundle.js:63146:5)

You need to add a key to the parent element of the return like this您需要像这样向返回的父元素添加一个键

return <p className='font-bold text-xl' key={i}>Rs. {v.DiscountPrice}</p>

But it's better to use a unique property of the object like key={v.id} if id exists但如果id存在,最好使用 object 的独特属性,例如key={v.id}

You are looping over你正在循环

data.map((v, i)=>{
        return <p className='font-bold text-xl'>Rs. {v.DiscountPrice}</p>
})

Just add a key to the return JSX只需在返回 JSX 中添加一个键

data.map((v, i)=>{
        return <p key={index} className='font-bold text-xl'>Rs. {v.DiscountPrice}</p>
})

If you have a unique identifier in the v object, use that如果您在 v object 中有唯一标识符,请使用该标识符

Refer => https://reactjs.org/docs/lists-and-keys.html#keys参考 => https://reactjs.org/docs/lists-and-keys.html#keys

I want code and API to fetch data from database buy passing query for one specific id. I tried the code but the code is throwing error. I have already connected database and I have already coded an API to fetch all the data from the database.

below i have attached my code下面我附上了我的代码

  app.get('/:Employee_id', (req,res) => {
            pool.getConnection((err, connection) =>{
                if(err) throw err;
                console.log('connected as id' + connection.threadId);
                
                connection.query('Select* from employee where Employee_id = ?', [req.params.Employee_id], (err, rows)=>{
                    connection.release();
                    
                    if(!err){
                        res.send(`employee with the id: ${Employee_id}`);
                    }
                    else{
                        console.log(err);
                    }
                });
            });
        });

暂无
暂无

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

相关问题 收到警告“警告:列表中的每个孩子都应该有一个唯一的”key“道具。” 当我的组件渲染时 - Getting warning “Warning: Each child in a list should have a unique ”key“ prop.” when my component render 列表中的每个孩子都应该有一个唯一的“关键”道具。 我做到了,但仍然看到这个错误 - Each child in a list should have a unique "key" prop. I made it, but still see this error 列表中的每个孩子都应该有一个唯一的“关键”道具。 即使我给了一把钥匙,而且它是独一无二的 - Each child in a list should have a unique “key” prop. Even though i am giving a key and its a unique one 警告:列表中的每个孩子都应该有一个唯一的“key”道具。 即使已经设置了密钥 - Warning: Each child in a list should have a unique "key" prop. Even after setting the key already 正在渲染对象数组的数组,不断得到“警告:列表中的每个孩子都应该有一个唯一的“键”道具。 - Was rendering arrays of arrays of objects, keep getting “Warning: Each child in a list should have a unique ”key“ prop.” 警告:列表中的每个孩子都应该有一个唯一的“关键”道具。 检查 `RenderComments` 的渲染方法 - Warning: Each child in a list should have a unique "key" prop. Check the render method of `RenderComments` 警告:列表中的每个孩子都应该有一个唯一的“关键”道具。 mapStateToProps - Warning: Each child in a list should have a unique "key" prop. mapStateToProps 列表中的每个孩子都应该有一个唯一的“key”道具。 检查`Form`的渲染方法 - Each child in a list should have a unique “key” prop. Check the render method of `Form` 警告:列表中的每个孩子都应该有一个唯一的“key”道具。 - ReactJS - Warning: Each child in a list should have a unique "key" prop. - ReactJS 警告:列表中的每个孩子都应该有一个唯一的“关键”道具。 如何解决这个问题? - Warning: Each child in a list should have a unique "key" prop. how to fix this?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM