web3-react icon indicating copy to clipboard operation
web3-react copied to clipboard

Web3ReactHooks return undefined when page is refreshed

Open berkaycirak opened this issue 2 years ago • 0 comments

Hi, I am using web3ReactHooks into my context. If I don't set the values into storage, they can't persist in refreshing. I mean, when user connects the wallet and refresh the page, wallet infos which come from hooks disappear. Therefore, I set a value into walletModal like that User should click the metamask button, then activate will be executed.

 if (connector === "Metamask") {
        await metaMask.activate();
        localStorage.setItem("isWalletConnected", true); 

Then, if user connected wallet, I activate the metaMask again into context in order to persist in refreshing

 if (localStorage.getItem("isWalletConnected")) {
    metaMask.activate();
  }

Is there any idea about that issue ? Should I set that values into localStorage.

berkaycirak avatar Sep 15 '22 08:09 berkaycirak