Comments (8)
Yeah I noticed this earlier and am working on a fix as we speak :) should be out today or tomorrow! Once it lands, happy to explain how the mechanism works
from web3-react.
Got it. I updated your code to use useRef
instead useState
since it's still trigger re-rendering:
const signer = useRef();
useEffect(() => {
if (context.library) {
signer.current = context.library.getSigner(context.account);
}
}, [context.library]);
and confirmed that it works as what I expected with 4.0.3. Thanks a lot for your help!!
from web3-react.
Thank you so much!!
from web3-react.
Ok @jinserk should be fixed in 4.0.3 (@latest), please let me know if you're still having issues! Sorry about the problem, it's because I was memoizing some of the manager functions, which were causing a re-render after certain state transitions.
from web3-react.
I tested 4.0.3 and have still the same issue. When I check the context.active
, it changes from false
at the first console msg to true
at the second one. However, when I get a log from MyComponent
, the myContext.active = true
at the both msgs. I guess the context.setConnector
call is behind the first rendering in MetaMaskComponent
, and this triggers second useEffect()
call since context
has been changed. So what my question is, do we have any hook before rendering in a component?
from web3-react.
that shouldn't be happening, sorry :/
i will take a look at this tomorrow. by the way, reproductions in a codesandbox are far easier for me to work with than copy-pasted code.
from web3-react.
I added my code snippets in codesandbox (https://codesandbox.io/s/rjwjmronr4).
And as testing, when unset connector after logout in MetaMask, I couldn't re-connect even though I logged in MetaMask again.
from web3-react.
Ok, this isn't happening because of web3-react. You're using a useEffect
that takes the context in the dependency array, so <MyComponent>
gets called twice, once on the initial context update, and once after the useEffect triggers to update the signer
state variable. I've also pasted code below which is a clearer way of doing what you're trying to do.
const [signer, setSigner] = useState();
useEffect(() => {
if (context.library) {
setSigner(context.library.getSigner(context.account))
}
}, [context.library])
Re. MetaMask, after logging out and logging back in, if you want to spam your users it can be as simple as:
useEffect(() => {
if (!context.active) {
context.setConnector('metaMask')
}
}, [context.active])
If they reject the connection attempt though then your app will hang, which is maybe why you should consider other patterns like a re-connect button, or something like that.
from web3-react.
Related Issues (20)
- How to connect Trezor wallet using web3-react v8
- How can I get provider url from connected wallet? HOT 2
- Why is `connector.deactivate` always undefined? HOT 1
- **The latest updates on your projects**. Learn more about [Vercel for Git ↗︎](https://vercel.link/github-learn-more)
- Walletconect v2 chains not supported
- V3-core
- TypeError: Object(...) is not a function (WalletConnectV2) HOT 1
- How can I sign a transaction using web3-react library?
- dotnet add package dotnetstandard-bip39 --version 1.0.2
- Something happend with intendation
- How can I send transaction to ethereum via metamask?
- tags` as well.beezywqp
- How can i connect okx wallet (web3-react v6) ??
- Did Uniswap abandon this repo? HOT 1
- gm
- How can i use network connection as a fallback connector? HOT 1
- Issue with useWeb3React chainId property when changing Network in MetaMask mobile (WalletConnect v2 connector) HOT 1
- WalleConnectV2 deactivate HOT 1
- connect function from useWalletConnect does not trigger the injectedWallet module automatically
- Missing or invalid. emit() chainId: eip155:11155111. & Cannot convert undefined or null to object at Function.keys (<anonymous>) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from web3-react.