Prevent flash of 404 on user profile page.

This commit is contained in:
jahooma 2021-12-15 23:56:03 -06:00
parent 5565bc5455
commit 4fd3f03fd3

View File

@ -6,7 +6,7 @@ import Error from 'next/error'
export default function UserProfile() { export default function UserProfile() {
const router = useRouter() const router = useRouter()
const [user, setUser] = useState<User | null>(null) const [user, setUser] = useState<User | null | 'loading'>('loading')
const atUsername = router.query.username as string | undefined const atUsername = router.query.username as string | undefined
const username = atUsername?.substring(1) || '' // Remove the initial @ const username = atUsername?.substring(1) || '' // Remove the initial @
useEffect(() => { useEffect(() => {
@ -16,6 +16,9 @@ export default function UserProfile() {
}, [username]) }, [username])
const errorMessage = `Who is this "${username}" you speak of..` const errorMessage = `Who is this "${username}" you speak of..`
if (user === 'loading') return <></>
return user ? ( return user ? (
<UserPage user={user} /> <UserPage user={user} />
) : ( ) : (