Next.js Discord

Discord Forum

Hydration errors when using 'use client';

Unanswered
Selkirk Rex posted this in #help-forum
Open in Discord
Selkirk RexOP
I started learning NextJS 14 with Supabase, but for some reason even though i'm using 'use client', i'm getting hydration errors.

I have a fairly simple page:

'use client';

import {supabase} from "@/src/lib/supabase";
import {useState} from "react";


export default function Login() {

    const [data, setData] = useState<{
        email: string, password: string,
    }>({
        email: '',
        password: ''
    })
    const login = async () => {
        console.log(data.email)
        console.log(data.password)
        try {

            let {data: dataUser, error} = await supabase.auth.signUp({
                email: data.email,
                password: data.password
            })

            if (dataUser) console.log(dataUser)

        } catch (error) {
            console.log(error)
            console.log('aaya')
        }
    }

    const handleChange = (e: any) => {
        const {name, value} = e.target;
        setData((prev: any) => ({
            ...prev,
            [name]: value,
        }))
    }
    return <div className='container mx-auto w-[400px]'>
        <div className='grid'>
            <label>Email</label>
            <input
                type='text'
                name='email'
                value={data?.email}
                onChange={handleChange}
            />
        </div>
        <div className='grid'>
            <label>Password</label>
            <input
                type='password'
                name='password'
                value={data?.password}
                onChange={handleChange}
            />
        </div>
        <div>
            <button onClick={login}>Sign Up</button>
        </div>
    </div>

}


What could be the issue? Thanks!

12 Replies

American
It's still getting rendered on the server, you will to do something like this:
if (isClient) {
  return null;
}
I'm using @uidotdev/usehooks for this purpose
Selkirk RexOP
No, no lastpass, why does LastPass matter? Also, what i've noticed is that the hydration errors dissapear and appear randomly. Is this perhaps a known bug or?
Should i downgrade a version?
Im on 14.1.0
usually happen on input and I saw you have input that's why I asked
Selkirk RexOP
Oh that can happen! I'll switch to a clean browser for development then
@Selkirk Rex Oh that can happen! I'll switch to a clean browser for development then
yep, try it with incognito and see if it still presist
@Ray yep, try it with incognito and see if it still presist
Selkirk RexOP
Thanks for the response, i'll send an update if everything is okay
In case anybody else has the same issue : )

\