'Track Solana wallet change in Web

I'm building a Web3 app while using Solana.
I'm using @solana/wallet-adapter for wallet connection

Code:

const Wallet = ({ children }) => {
// The network can be set to 'devnet', 'testnet', or 'mainnet-beta'.
const network = WalletAdapterNetwork.Devnet;

// You can also provide a custom RPC endpoint.
const endpoint = useMemo(() => clusterApiUrl(network), [network]);

// @solana/wallet-adapter-wallets includes all the adapters but supports tree shaking and lazy loading --
// Only the wallets you configure here will be compiled into your application and only the dependencies
// of wallets that your users connect to will be loaded.
const wallets = useMemo(
() => [
   new PhantomWalletAdapter(),
   new SlopeWalletAdapter(),
   new SolflareWalletAdapter(),
   new TorusWalletAdapter(),
   new LedgerWalletAdapter(),
   new SolletWalletAdapter({ network }),
   new SolletExtensionWalletAdapter({ network }),
],[network]);

return (
  <ConnectionProvider endpoint={endpoint}>
    <WalletProvider wallets={wallets} autoConnect>
      <WalletModalProvider>
        <WalletMultiButton />
        <WalletDisconnectButton />
        {children}
      </WalletModalProvider>
    </WalletProvider>
  </ConnectionProvider>
);
};

It's a basic components. Same as a presented in @solana/wallet-adapter docs

The problem:
After connecting some wallet manager(let's say Phantom, for instance), I'm getting all the information I need. But after changing wallet -- I don't see any updates in my app.

The question is
How can I handle this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source