简体   繁体   English

为什么当我使用 avatar antd 时反应会报错?

[英]Why react get me error when I use avatar antd?

I need your help.我需要你的帮助。 I didnt know how to fix this error and I dont understand why get me this error:我不知道如何修复此错误,也不明白为什么会出现此错误:

Error: Objects are not valid as a React child (found: object with keys {$$typeof, render}). If you meant to render a collection of children, use an array instead.

and my page, Error there when I use function <UserAvatar />和我的页面,当我使用 function <UserAvatar />时出现错误

import {Auth} from '../../context'
import config from '../../config'
import {Avatar} from 'antd'
import { UserOutlined } from '@ant-design/icons'
import { useConversation } from '../../conversation'

function UserAvatar(){
    return <div className="photo_section">
        <Avatar icon={UserOutlined} />
    </div>
}

export default function Conversations(){
    
    const {conversations,setConversationNumber,conversationNumber} = useConversation()
    return (
        <>
            {
                conversations.length === 0 ? <div> You dont have any chat! </div>:
                conversations.map( (i)=>(
                    <div 
                        key={i._id} 
                        
                        onClick = { ()=>{ 
                                setConversationNumber(i._id)
                            }
                        }
                        
                        className={"message_item " + (i._id === conversationNumber ? " _color ": "") }
                        
                    >
                        <UserAvatar />
                        
                        
                        <div className="message_section">
                            <div className="message_name">
                                <h6 className="_chat_user_name" > {i.name} </h6>
                            </div>
                            <div className="message_text">
                                <div className="text_mes">
                                    Hello how are you?
                                </div>
                                <div className="message_time">
                                    10s
                                </div>
                            </div> 

                        </div>

                    </div>))}  </>
    )
}

If you check the Avatar API you'll see that the icon prop is of type ReactNode .如果你检查Avatar API你会看到icon属性的类型是ReactNode This means you need to pass the component as JSX, versus as a class or function component reference.这意味着您需要将组件作为 JSX 传递,而不是作为 class 或 function 组件引用传递。

function UserAvatar() {
  return <div className="photo_section">
      <Avatar icon={<UserOutlined />} />
  </div>
}

暂无
暂无

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

相关问题 当我使用 npm 创建反应应用程序时,我收到此错误 - when I use npm to create react app ,I get this error 为什么我在安装 react 应用程序时,它给了我这个错误? - Why when im installing react app, it gives me this error? 当我编写 npm start 并收到此错误时,我的反应应用程序没有启动,任何人都可以帮助我,我是新来的反应。 我正在使用 Acode(Editor) 和 termux - My react app does not start when I write npm start and get this error can anyone please help me I am new to react. I am using Acode(Editor) and termux 为什么在使用 react-native juspay 开始付款时会出现此错误? - Why do I get this error when I start a payment using react-native juspay? 为什么在我尝试使用我的模型时出现错误? - why do i get an error when i try to use my models? 当我尝试更改我的 Discord 头像时,为什么会收到“400:错误请求”? - Why am I getting a '400: Bad Request' when i try to change my Discord avatar? 为什么在尝试将 Multer 用于动态路径时会出现此错误? - Why do I get this error when trying to use Multer for dynamic path? opensslErrorStack 反应错误:当我尝试启动我的项目时,它向我显示此错误 - opensslErrorStack react error : when i try to start my project it show me this error 刷新页面后,为什么Express / React Webapp会给我500错误? - Why does my Express/React webapp give me a 500 error once I refresh the page? 使用 router.get('/me', (res,req) =&gt; {}) 时如何访问身份验证信息 - How do I access the auth information when I use router.get('/me', (res,req) => {})
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM