Notification Provider 组件在使用 React Moralis 的 NextJS 中导致水合错误 - FCC Pat Collins 全栈开发课程

问题描述 投票:0回答:1

我陷入了第 10 课,在下一个应用程序中的layout.js 文件中的包装器之后我无法继续前进

我的Layout.js:

"use client"
import { Inter } from "next/font/google"
import "./globals.css"
import { MoralisProvider } from "react-moralis"
import { NotificationProvider } from "web3uikit"

const inter = Inter({ subsets: ["latin"] })

/* export const metadata = {
    title: "Smart Contract Lottery FCC",
    description: "Generated by create next app",
} */

export default function RootLayout({ children }) {
    return (
        <MoralisProvider initializeOnMount={false}>
            <NotificationProvider>
                <html lang="en">
                    <head>
                        <title>Smart Contract Lottery</title>
                    </head>
                    <body className={inter.className}>{children}</body>
                </html>
            </NotificationProvider>
        </MoralisProvider>
    )
}

我的page.js :

"use client"
import { ConnectButton } from "web3uikit"
import LotteryEntrance from "../../components/LotteryEntrance"
export default function Home() {
    return (
        <main className="flex min-h-screen flex-col items-center justify-between p-48">
            <div className="max-w-2xl w-full items-center justify-between font-mono text-5xl">
                Smart Contract Lottery
            </div>
            <div className="flex flex-col gap-y-8 max-w-5xl justify-between items-center text-2xl p-12">
                Decentralized Lottery
                <ConnectButton moralisAuth={false} />
                <LotteryEntrance />
            </div>
        </main>
    )
}

我遇到的错误:

app-index.js:33 Warning: In HTML, <div> cannot be a child of <#document>.
This will cause a hydration error.
    at div
    at O2
    
    Uncaught Error: Hydration failed because the initial UI does not match what was rendered on the server.
    
    An error occurred during hydration. The server HTML was replaced with client content in <#document>.
    
    Uncaught DOMException: Failed to execute 'appendChild' on 'Node': Only one element on document allowed.
    
     Hydration failed because the initial UI does not match what was rendered on the server.
     
     There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.
     
     Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.
     
     he above error occurred in the <StrictMode> component:


Consider adding an error boundary to your tree to customize error handling behavior.
Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.

Uncaught AggregateError
    at flushSyncWorkAcrossRoots_impl 

我尝试将layout.js组件包装在一个单独的文件中,并将其导出到layout.js中,但随后又出现了同样的问题。我是不是错过了什么?

更新 好吧,正在尝试不同的方法来使用通知组件,并且在我的 page.js 中执行此操作消除了错误:

                <NotificationProvider>
                    <LotteryEntrance />
                </NotificationProvider>

我现在得到了这个 - 但我的 UI 现在正在渲染,之前我没有得到任何 UI 元素:

   app-index.js:33 Warning: Extra attributes from the server: data-new-gr-c-s-check-loaded,data-gr-ext-installed
    at body
    at html
    at MoralisProvider (

知道为什么吗?

javascript next.js13 react-fullstack
1个回答
0
投票

谁买彩票,买彩票的理由都是他们的事,仅仅因为想碰碰运气就说别人是失败者,这真是太糟糕了。太多人太关心别人的所作所为并取笑他们,我的好朋友菲利普(Philip)向我介绍了彩票,他是一个赌徒,我玩了6个月彩票,但我没有赢得一美元。当我偶然在互联网上找到帮助时,我正在放弃。有人正在见证一个名叫索图的人的善良。索图是一位精神医生,他在一次精神遭遇后给出中奖号码。我按照指示通过电子邮件联系了他。剩下的就是历史了。我从强力球彩票中赢得了 200 万美元。索图博士就是这个名字。电子邮件:Greatsotuspell@saintly。 com

© www.soinside.com 2019 - 2024. All rights reserved.