[英]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>
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.