GithubHelp home page GithubHelp logo

Comments (11)

damianlluch avatar damianlluch commented on June 8, 2024

I tried with this library in an project with Next.
And I get this error:

TypeError: dispatch is not a function

image

I reproduced only the example from de main page.

Any suggestions?

thanks!

from use-metamask.

mdtanrikulu avatar mdtanrikulu commented on June 8, 2024

Heya! Thanks for the issue. I tried to reproduce the error with nextjs create app template but failed.

image



Could you give me more details? If you press useMetamask.js?cdc:138 url in second line of the error you got, this may route you to code block causing the issue.

from use-metamask.

damianlluch avatar damianlluch commented on June 8, 2024

Heya! Thanks for the issue. I tried to reproduce the error with nextjs create app template but failed.

image

Could you give me more details? If you press useMetamask.js?cdc:138 url in second line of the error you got, this may route you to code block causing the issue.

perfect!, you can share this example?

from use-metamask.

mdtanrikulu avatar mdtanrikulu commented on June 8, 2024

sure, here you go. but please let me know the cause of the code line by following the instruction from my previous message. so I can see what I can improve.

nextjsapp.zip

from use-metamask.

damianlluch avatar damianlluch commented on June 8, 2024

Perfect, now I'll look at the code you sent, and I'll let you know.

from use-metamask.

damianlluch avatar damianlluch commented on June 8, 2024

I have the issue.

image

image

from use-metamask.

mdtanrikulu avatar mdtanrikulu commented on June 8, 2024

Oh, I guess I know the issue now. Did you wrap your root component with <MetamaskStateProvider> ?
As shown here in first step.

Your root component must look like this;

import React                     from 'react';
import ReactDOM                  from 'react-dom';
import { MetamaskStateProvider } from "use-metamask";
import App                       from './App';

ReactDOM.render(
    <MetamaskStateProvider>
      <App />
    </MetamaskStateProvider>
  document.getElementById('root')
);

You can also see _app.js file that I shared as nextjs example with you.

from use-metamask.

damianlluch avatar damianlluch commented on June 8, 2024

Hi, yes I have wrapped it over pages/_app.js

from use-metamask.

mdtanrikulu avatar mdtanrikulu commented on June 8, 2024

Hi, yes I have wrapped it over pages/_app.js

That's interesting. Is there any chance I can see your implementation if it's open source?

The only way I was able to reproduce your issue, when I don't use MetamaskStateProvider wrapper, thus;

  const dispatch = useContext(MetaDispatchContext);

in my hook implementation returns undefined. The component you call useMetamask hook must be child or descendant of this wrapped root component. Other than that I could not find any other case this can happen.

from use-metamask.

mdtanrikulu avatar mdtanrikulu commented on June 8, 2024

Hey @damianlluch! Is it still a problem on your side? Is there anything I can help there?

from use-metamask.

mdtanrikulu avatar mdtanrikulu commented on June 8, 2024

Closing this issue due to inactivity, feel free to open if anything related this topic arise.

from use-metamask.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.