I have an Effect hook in a React component that sets up and initialises a class that I use to communicate with a backend server:

```js
const SignalProvider = ({url, children}) => {
  let [sigErr, setSigErr] = useState("")
  let [token, setToken] = useContext(TokenContext)
  let [signaller, setSignaller] = useState()

  useEffect(() => {
    if (!signaller) {
      const s = new Signaller(url, (err) => setSigErr(err))
      setSignaller(s)
    }

    if (token && signaller) {
      signaller.setToken(token)
      signaller.setSetTokenCallback(setToken) // Adding this line causes an infinite loop
      signaller.connect()
    }

  }, [url, token, signaller, setToken, authError]) 

  ...
}

```

However, adding the line `signaller.setSetTokenCallback(setToken)` causes an infinite loop of re-rendering. Without this line it works as expected.

All `setSetTokenCallback` does is:

```js
setTokenCallback(f) {
  this.setTokenCallback = f
}

```

Which I don't think should matter.

Whats the best way to prevent the loop?