'React strict mode breaks application in development with OAuth

In my OAuth flow, the token can only be called once, then it 404's. In React strict mode, it renders my component twice, which invokes a call to my back-end. The second call invalidates my token. This is a pain when developing (I know this is disabled in production). Is there a viable workaround? I've tried this state hack, but it doesn't work.

  const [code, setCode] = useState("")
  useEffect(() => {
    setCode("active")
    if (code == "") {
      forwardAuthCode();
    }
  }, [code])

The function invocation makes a back-end call to redeem the token from the auth code in OAuth.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source