简体   繁体   English

我的组件中已经有一个密钥,但为什么它仍在寻找唯一的密钥?

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

Hello{videoTitle}你好{videoTitle}

) } //im just trying to print out the videoTitle here.. but even the Hello is not rendering. ) } //我只是想在这里打印出 videoTitle.. 但即使是Hello也没有呈现。

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.

相关问题 React 应用程序抛出关于键的错误,但我已经在顶层分配了一个唯一键 - React app throwing error about key, but I have already assigned a unique key at the top level 为什么当已经有一个 key prop 时,这个警告会一直出现? 警告:列表中的每个孩子都应该有一个唯一的“key”道具 - Why does this warning keep appearing when there is already a key prop? Warning: Each child in a list should have a unique “key” prop 列表中的每个孩子都应该有一个唯一的“关键”道具。 我做到了,但仍然看到这个错误 - Each child in a list should have a unique "key" prop. I made it, but still see this error 我已经输入了一个独特的“关键”道具,但仍然有错误要求我在 React 中输入它 - I have input a unique "key" prop but still got error asking me to input it in React 我有API密钥,但仍然收到MissingKeyMapError - I have API key, but still getting MissingKeyMapError 收到警告“警告:列表中的每个孩子都应该有一个唯一的”key“道具。” 当我的组件渲染时 - Getting warning “Warning: Each child in a list should have a unique ”key“ prop.” when my component render 每个子列表键都是唯一的,但我仍然在控制台中收到错误消息。 反应器 - Each child list key is unique yet I still get the error in my console. Reactjs 当每个键已经是唯一的时,列表中的每个孩子都应该有一个唯一的“键”警告 - Each child in a list should have a unique “key” warning when every key is already unique 列表中的每个孩子都应该有一个独特的“关键”道具。 但我没有调用任何组件 - Each child in a list should have a unique "key" prop. but i'm not calling any component 唯一键是唯一的,已分配给 key prop,但仍然出现错误……但仅在一个组件中 - unique keys are unique, are assigned to key prop, but still getting error… but only in one component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM