Okta-react: calling useOktaAuth multiple times? useOktaAuth vs useEffect?

I’m running into rare hard-to-debug issues when using okta-react library.

I suspect that I’m misusing either useOktaAuth hook itself or some useEffect hooks where I pass authState / authService as dependencies.

So, my questions:

  1. Is it ok to call useOktaAuth multiple times in a single component rendering tree?
  2. The documentation says about useOktaAuth:

Using this hook will trigger a re-render when the authState object updates.

But there’s an official example in the documentation doing this:

  const { authState } = useOktaAuth();
  useEffect( () => { 
       ... some code
  }, [authState] );

Why would you do useEffect with authState as a dependency if useOktaAuth already guarantees a re-render when authState changes? I’m confused on how this works.
3. Does it make any sense to do useEffect(…, authService)? Can authService object change?

1 Like