manifold/web/pages/[username]/index.tsx

24 lines
718 B
TypeScript
Raw Normal View History

import { useRouter } from 'next/router'
import React, { useEffect, useState } from 'react'
import { getUserByUsername, User } from '../../lib/firebase/users'
2021-12-16 02:11:29 +00:00
import { UserPage } from '../../components/user-page'
import Error from 'next/error'
export default function UserProfile() {
const router = useRouter()
const [user, setUser] = useState<User | null>(null)
const { username } = router.query as { username: string }
useEffect(() => {
if (username) {
getUserByUsername(username).then(setUser)
}
}, [username])
const errorMessage = `Who is this "${username}" you speak of..`
return user ? (
<UserPage user={user} />
) : (
<Error statusCode={404} title={errorMessage} />
)
}