'Header不能用作JSX组件。其返回类型“Promise”不是有效的JSX元素。类型“Promise”缺少类型“ReactElement<any,any>”中的以下属性:类型, prop ,钥匙
import Image from "next/image";
import Link from "next/link";
import LogoutButton from "./LogoutButton";
import { unstable_getServerSession } from "next-auth/next";
async function Header() {
const session = await unstable_getServerSession();
if (session)
return (
<header className="sticky top-0 z-50 bg-white flex justify-between items-center p-10 shadow-sm">
<div className="flex space-x-2">
<Image
className="rounded-full mx-2 object-contain"
height={10}
width={50}
src={session.user?.image!}
alt="Profile Picture"
/>
<div>
<p className="text-blue-400">Logged in as:</p>
<p className="font-bold text-lg">{session.user?.name}</p>
</div>
</div>
<LogoutButton />
</header>
);
return (
<header className="sticky top-0 z-50 bg-white flex justify-center items-center p-10 shadow-sm">
<div className="flex flex-col items-center space-y-5">
<div className="flex space-x-2 items-center">
<Image
src="https://links.papareact.com/jne"
height={10}
width={50}
alt="Logo"
/>
<p className="text-blue-400">Welcome to Meta Messenger</p>
</div>
<Link
href="/auth/signin"
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
>
Sign In
</Link>
</div>
</header>
);
}
export default Header;
我尝试使用异步函数
1条答案
按热度按时间y53ybaqx1#
异步函数组件的类型还没有完全登陆。您可以订阅this PR。一旦它登陆,升级
@types/react
和typescript
应该就可以了。在此之前,您可以进行类型转换,例如。
或
在每一个使用站点上跳这支舞: