wagmi: useConfig must be used within WagmiConfig

Is there an existing issue for this?

  • I have searched the existing issues

Package Version

1.4.1

Current Behavior

Package version: 1.4.1

I have a react native expo app and I try to integrate wagmi with RainbowKit. After I completed the installation process and open the app I get this error:

Unhandled Rejection (Error): useConfig must be used within WagmiConfig.

This is the implementation code:

const { chains, publicClient, webSocketPublicClient } = configureChains(
    [
      mainnet,
      polygon
    ],
    [publicProvider()]
)
  
const { connectors } = getDefaultWallets({
    appName: 'test',
    projectId: 'b67c616c2f896b215dff2499d07587ed',
    chains,
})
  
const wagmiConfig = createConfig({
    autoConnect: true,
    connectors,
    publicClient,
    webSocketPublicClient,
})

export default function App() {
    return (
        <WagmiConfig config={wagmiConfig}>
            <RainbowKitProvider chains={chains}>
                <ConnectButton />
            </RainbowKitProvider>
        </WagmiConfig>
    )
}

It’s worth noted that I have a separate package inside my project where I install the dependencies and make a build with webpack so I can have the libraries loaded already when I use them, but I don’t see how this can be an issue, the only thing I do is import them from that package

Expected Behavior

Should work as expected and load the ConnectButton on the app

Steps To Reproduce

No response

Link to Minimal Reproducible Example (StackBlitz, CodeSandbox, GitHub repo etc.)

No response

Anything else?

No response

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Reactions: 3
  • Comments: 16 (3 by maintainers)

Most upvoted comments

i ran into this error in a correctly configured project because i had some funky import loop going on related to exposing some chains from viem/chains in a dependency that my next13 project was importing in order to use in configureChains… i have no clue what the actual issue was but it may be helpful to future searchers to look at how they’re importing chains and to streamline that as much as possible. in my case i had a dependency called config that had two files chains.ts and config.ts (hah), both exported in a bullet file index.ts. chains.ts exposed some viem/chains and config.ts imported them. i actually only needed the type of them in this file, so that fixed my issue.

// NOTE: importing this value directly makes the nextjs build blow up, idk
import type { SUPPORTED_CHAINS } from "./chains";

I update wagmi, viem and @rainbow-me/rainbowkit to last version and error disappear. updaet this package everywhere

This might be useful for other users:

Not including WagmiConfig or using Wagmi hooks like useAccount() in the same component that contains WagmiConfig will cause this error: “Error: useConfig must be used within WagmiConfig.”

All Wagmi hooks must be used inside <WagmiConfig />. In the first example you posted, useAccount is not inside it.