apibara / starknet-react

A collection of React providers and hooks for StarkNet
https://starknet-react.com
MIT License
369 stars 147 forks source link

:bug: useNetwork doesn't detect network change (starknet-react v1.0.2) #283

Closed florian-bellotti closed 1 year ago

florian-bellotti commented 1 year ago

The useNetwork hook doesn't detect network change.

https://github.com/apibara/starknet-react/blob/a725fa891960f95a0dbf8994a420ff23f2738e34/packages/core/src/hooks/network.ts#L31

Replacing line 31 with something like this could fix the bug.

use [chain, setChain] = useState<Chain>(); // TODO: retrieve the default network value
useEffet(() => {
    if (!library) return;
    library.getChainId().then((chainId) => setChain(chainById(chainId)));
  }, [library])
fracek commented 1 year ago

You're right. What's happening is that the query doesn't have a key so it won't refresh. Fix incoming.