MoralisWeb3 / react-moralis

Hooks and components to use Moralis in a React app
MIT License
624 stars 166 forks source link

react-moralis in Next.js 14 #326

Open ali0120 opened 11 months ago

ali0120 commented 11 months ago

Issue Description

I'm encountering an issue related to the compatibility or initialization of react-moralis in a Next.js 14 project. The error I'm facing is:

  1. Code Snippet: In my Next.js 14 project, I'm using the following code to set up MoralisProvider:
    
    <MoralisProvider initializeOnMount={false}>
    <Suspense fallback={<Loading />}>
    {children}
    </Suspense>
    </MoralisProvider>

Return This Error

Server Error Error: (0 , react__WEBPACK_IMPORTED_MODULE_0__.createContext) is not a function

This error happened while generating the page. Any console logs will be displayed in the terminal window.

fraolb commented 7 months ago

Hello @ali0120 I have also faced same kind of issue, how I solved it is by moving the MoralisProvider to the Page.js and wrapping my main page instead of the layout.js file. and also make sure to add "use client"; in the page Page.js.

ajibade-dev commented 7 months ago

Hello @ali0120 I have also faced same kind of issue, how I solved it is by moving the MoralisProvider to the Page.js and wrapping my main page instead of the layout.js file. and also make sure to add "use client"; in the page Page.js.

hi @fraolb please is it possible for you to drop a snippet of how you wrapped your code to work with the moralis provider? I am getting a error and also not been able to use the useMoralis() hook

fraolb commented 7 months ago

Hi @ajibade-dev you can refer to this repo https://github.com/fraolb/lottery-smartcontract-project