Skip to content

Commit

Permalink
fix Hydration error on root page
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigoncalves committed Feb 19, 2025
1 parent 9f083b5 commit 2e2c84f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/app/login/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Footer } from '@/components/Footer'
import { Headline } from '@/components/Typography'
import { cn } from '@/lib/utils'
import Image from 'next/image'
import { useRouter } from 'next/navigation'
import { useEffect, useState } from 'react'
import { useAccount } from 'wagmi'
Expand All @@ -10,6 +9,7 @@ import { GetStarted } from './GetStarted'
import { BG_IMG_CLASSES } from '@/shared/utils'
import { HeaderText } from '@/components/HeaderText/HeaderText'
import { DeviceWarning } from '@/components/DeviceWarning'

export const Login = () => {
const { isConnected, address } = useAccount()
const [hasMounted, setHasMounted] = useState(false)
Expand Down
13 changes: 13 additions & 0 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@
import { useAccount } from 'wagmi'
import { Login } from './login'
import User from './user/page'
import { useEffect, useState } from 'react'

export default function Home() {
const { isConnected } = useAccount()
const [hasMounted, setHasMounted] = useState(false)

useEffect(() => {
// This is to prevent Hydration error on client side
// because useAccount hook is not available on server side
setHasMounted(true)
}, [])

if (!hasMounted) {
return null
}

if (isConnected) {
return <User />
}
Expand Down

0 comments on commit 2e2c84f

Please sign in to comment.