apibara / starknet-react

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

useAccount with onConnect callback functions causes maximum update depth exceeded #458

Closed TudorEsan closed 4 months ago

TudorEsan commented 4 months ago

when passing a callback function to the useAccount hook the app will continuously rerender.

this is the code that causes the bug:

export const DAppProvider = () => {
  useAccount({
    onConnect: () => {
       console.log('Connected to StarkNet');
     },
    // onDisconnect: () => {
    //   console.log('Disconnected from StarkNet');
    // },
  });

  return null;
};

I'm using "@starknet-react/core": "^2.8.3" and nextjs v14.1

the error i get:

Warning: Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn't have a dependency array, or one of the dependencies changes on every render.
Screenshot 2024-07-02 at 11 18 22
od-hunter commented 4 months ago

Hi @TudorEsan Can I be assigned this?

fracek commented 4 months ago

I removed the callbacks in v3 because they were causing too many issue. You should use useEffect with the address/account in the dependency list to invoke a function when the value changes.

fracek commented 4 months ago

Closing because there is no way to fix it and in v3 won't be an issue.