在我的next.js web应用中-
interface NavbarProps {
currentUser: {
id?: String
username?: string
name?: string
}
}
const Navbar: React.FC<NavbarProps> = ({ currentUser }) => {
console.log(currentUser)
console.log(currentUser?.id )
在上面的代码中,当我尝试打印currentUser时,它会按预期打印,即。
{
currentUser: {
id: '65255530a08db2db2f91e7e9',
email: '[email protected]',
emailverified: null,
hashedPassword: 'xyz',
username: 'abc',
name: 'abc',
bio: null,
profilepic: null,
}
}
但当我尝试console.log的id;它总是打印为“undefined”
我从这里传递currentUser-
import Navbar from '@/components/headersAndFooters/navbar'
import { serverAuth } from '@/lib/serverAuth'
import React from 'react'
interface LayoutProps {
children: React.ReactNode
}
const layout: React.FC<LayoutProps> = async({ children }) => {
let currentUser = await serverAuth()
return (
<div>
<Navbar currentUser={currentUser as any}/>
{children}
</div>
)
}
export default layout;
我试图在删除.next文件后重新启动服务器;甚至尝试在不同的浏览器;我还尝试使用.jsx将其打印到屏幕上
1条答案
按热度按时间mf98qq941#
您的对象与声明不同
应为:
此外,尽量避免使用任何