web3modal-react-native icon indicating copy to clipboard operation
web3modal-react-native copied to clipboard

[feature] Is it possible for useAppkit to expose the full appKit instance?

Open Holybasil opened this issue 2 months ago • 1 comments

What problem does this new feature solve?

The switchNetwork function requires an AppKitNetwork, but the networks exported from '@reown/appkit/networks' are not in the AppKitNetwork format.

I noticed that AppKit internally formats these networks and attaches them to this.networks, but unfortunately, this data is not exported.

As a result, I have to manually reformat the imported network from '@reown/appkit/networks' like this

appKitNetwork: { ...arbitrum, chainNamespace: 'eip155', caipNetworkId: 'eip155:42161' }

This approach is less than ideal and feels a bit clunky. I’m opening this issue to propose exporting the appKit instance, so developers can directly access the data and functions it provides.

Describe the solution you'd like

export const useAppKit = (): UseAppKitReturn => {
  const context = useContext(AppKitContext);

  if (context === undefined) {
    throw new Error('useAppKit must be used within an AppKitProvider');
  }

  if (!context.appKit) {
    // This might happen if the provider is rendered before AppKit is initialized
    throw new Error('AppKit instance is not yet available in context.');
  }

  const { appKit } = context;

  const stableFunctions = useMemo(() => {
    if (!context.appKit) {
      throw new Error('AppKit instance is not available');
    }

    return {
      open: context.appKit.open.bind(context.appKit),
      close: context.appKit.close.bind(context.appKit),
      disconnect: (namespace?: ChainNamespace) =>
        context.appKit!.disconnect.bind(context.appKit!)(namespace),
      switchNetwork: context.appKit.switchNetwork.bind(context.appKit),


    };
  }, [context.appKit]);

  return { appkit, ...stableFunctions };
};

Holybasil avatar Oct 16 '25 02:10 Holybasil

hey @Holybasil 👋 @reown/appkit/networks is not part of the react native SDK but from web. But i'll check this, it would be good to accept viem/chains too

ignaciosantise avatar Oct 16 '25 12:10 ignaciosantise