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