[英]i already have a Key in my component but why is it still looking for a unique key?
I am new to react js and i'm trying to pass a data from one component to another using Link to and this method is what i found on the net..我是反应js的新手,我正在尝试使用Link to将数据从一个组件传递到另一个组件,这种方法是我在网上找到的..
ERROR: index.js:1 Warning: Each child in a list should have a unique "key" prop.错误:index.js:1 警告:列表中的每个孩子都应该有一个唯一的“关键”道具。
Check the render method of Videos
.检查
Videos
的渲染方法。 See https://reactjs.org/link/warning-keys for more information.有关详细信息,请参阅https://reactjs.org/link/warning-keys 。 at http://localhost:3000/static/js/vendors~main.chunk.js:134999:31 at Videos (http://localhost:3000/static/js/main.chunk.js:5570:81) at div at Route (http://localhost:3000/static/js/vendors~main.chunk.js:135601:29) at Switch (http://localhost:3000/static/js/vendors~main.chunk.js:135803:29) at Router (http://localhost:3000/static/js/vendors~main.chunk.js:135232:30) at BrowserRouter (http://localhost:3000/static/js/vendors~main.chunk.js:134853:35) at div at App
在 http://localhost:3000/static/js/vendors~main.chunk.js:134999:31 在视频 (http://localhost:3000/static/js/main.chunk.js:5570:81) 在路由上的 div (http://localhost:3000/static/js/vendors~main.chunk.js:135601:29) 在 Switch (http://localhost:3000/static/js/vendors~main.chunk.js :135803:29) 在路由器 (http://localhost:3000/static/js/vendors~main.chunk.js:135232:30) 在 BrowserRouter (http://localhost:3000/static/js/vendors~main .chunk.js:134853:35) 在应用程序的 div
Videos.js视频.js
function Videos() { function 视频(){
const [vids, setVids] = useState([]);
useEffect(() => {
db.collection('videos').orderBy('videoDate', 'desc').onSnapshot(snapshot => {
setVids(snapshot.docs.map(doc => ({
data: doc.data(),
id: doc.id
})))
})
}, []);
return (
<div className="Videos">
<h2> Available Lessons </h2>
<div className="Videos__uploads">
{
vids.map(({ id, data }) => (
<Link to={{ pathname: `/play/${id}`, data: data}}>
{console.log(id)}
<VideoCard
key={id}
videoTitle={data.videoTitle}
videoDate={data.videoDate}
videoCaption={data.videoCaption}
videoUrl={data.videoUrl}
/>
</Link>
))
}
</div>
</div>
)
} }
export default Videos;导出默认视频;
VideoPlayer.js function VideoPlayer({ videoTitle }) { return ( VideoPlayer.js function VideoPlayer({ videoTitle }) { return (
but my focus on this question is why is it still looking for a key when i already put a key on?但是我对这个问题的关注是为什么当我已经放上钥匙时它仍在寻找钥匙?
You need to give an unique key to Link
not to VideoCard
.您需要为
Link
而不是VideoCard
提供唯一的密钥。
vids.map(({ id, data }) => (
<Link key={id} to={{ pathname: `/play/${id}`, data: data}}>
{console.log(id)}
<VideoCard
videoTitle={data.videoTitle}
videoDate={data.videoDate}
videoCaption={data.videoCaption}
videoUrl={data.videoUrl}
/>
</Link>
))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.