#Help: Text content does not match server-rendered HTML.

6 messages · Page 1 of 1 (latest)

indigo hull
#

I make a random number generator, and i wanted it to only work on the client side. so i added the 'use client' declaration on the first line. but the error is shown.

'use client'

import {create} from 'zustand'
import {nanoid} from "nanoid";

interface BearState {
    bears: string
}

const useBearStore = create<BearState>()((set) => ({
    bears: nanoid(),
}))

export function _Chat() {
    const bearStore = useBearStore();

    console.log("------", bearStore.bears)

    return (
        <div>
            {bearStore.bears}
        </div>
    )
}


export default function Home() {
    return (
        <div>
            <_Chat/>
        </div>
    )
}
tulip prismBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

dapper kiln
indigo hull
#
'use client'

import {create} from 'zustand'
import {nanoid} from "nanoid";
import {NoSSR} from "next/dist/shared/lib/lazy-dynamic/dynamic-no-ssr";
import {Suspense} from "react";

interface BearState {
    bears: string
}

const useBearStore = create<BearState>()((set) => ({
    bears: nanoid(),
}))

export function _Chat() {
    let bearStore = useBearStore();
    console.log(bearStore.bears)


    return (
        <div>
            {bearStore.bears}
        </div>
    )
}

export default function Home() {
    return (
        <div>
            <Suspense fallback={<div>Oop, any error</div>}>
                <NoSSR>
                    <_Chat/>
                </NoSSR>
            </Suspense>

        </div>
    )
}
#
'use client'

import {create} from 'zustand'
import {nanoid} from "nanoid";
import dynamic from "next/dynamic";

interface BearState {
    bears: string
}

const useBearStore = create<BearState>()((set) => ({
    bears: nanoid(),
}))

export function _Chat() {
    let bearStore = useBearStore();
    console.log(bearStore.bears)


    return (
        <div>
            {bearStore.bears}
        </div>
    )
}

const Chat = dynamic(async () => (await import("@/app/page"))._Chat, {ssr: false});

export default function Home() {
    return (
        <div>
            <Chat/>
        </div>
    )
}