Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read properties of null (reading 'useContext') #78

Open
billsbooth opened this issue Oct 23, 2022 · 1 comment
Open

Comments

@billsbooth
Copy link

Just following the tutorial on a next.js setup, and getting TypeError: Cannot read properties of null (reading 'useContext') when trying to call useWallet();

import '../styles/globals.css'
import type { AppProps } from 'next/app'

import {
  WalletProvider,
  HippoWalletAdapter,
  AptosWalletAdapter,
  HippoExtensionWalletAdapter,
  MartianWalletAdapter,
  FewchaWalletAdapter,
  PontemWalletAdapter,
  SpikaWalletAdapter,
  RiseWalletAdapter,
  FletchWalletAdapter,
  TokenPocketWalletAdapter,
  ONTOWalletAdapter,
  SafePalWalletAdapter
} from '@manahippo/aptos-wallet-adapter';

const wallets = [
  new HippoWalletAdapter(),
  new MartianWalletAdapter(),
  new AptosWalletAdapter(),
  new FewchaWalletAdapter(),
  new HippoExtensionWalletAdapter(),
  new PontemWalletAdapter(),
  new SpikaWalletAdapter(),
  new RiseWalletAdapter(),
  new FletchWalletAdapter(),
  new TokenPocketWalletAdapter(),
  new ONTOWalletAdapter(),
  new SafePalWalletAdapter(),
];

function MyApp({ Component, pageProps }: AppProps) {
  <WalletProvider
      wallets={wallets}
      autoConnect={true}
      onError={(error: Error) => {
        console.log('Handle Error Message', error);
      }}>
    <Component {...pageProps} />
  </WalletProvider>
}

export default MyApp
import type { NextPage } from 'next'
import { AptosWalletName, useWallet } from "@manahippo/aptos-wallet-adapter"

const { connect } = useWallet();

const Home: NextPage = () => {
  return (
    <div>
      <button onClick={() => { connect(AptosWalletName); }} > Connect </button>
    </div>
  )
}

export default Home

Screen Shot 2022-10-23 at 4 08 58 PM

@quagliero
Copy link

@kingaptos your hook call needs to be inside the render function:

const Home: NextPage = () => {

  const { connect } = useWallet();

  return (
    <div>
      <button onClick={() => { connect(AptosWalletName); }} > Connect </button>
    </div>
  )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants