DEV Community

Discussion on: How to mimic componentDidUpdate() with React Hooks

Collapse
 
alsmith808 profile image
Alan Smith • Edited

Thanks Rudy, I believe you may have got me out of a jam with your suggestion of putting the if statement in useEffect. In my use case i need to watch for a change in the url as my app gets a redirect back from an api with a token.

( when path !== '/' means I have received a token from the api)

So now I can check it but only do something if I have the token, before I was getting a bit confused about needing useMemo or useRef.

Surprised I didn't think of your solution, perhaps I had it in my head that you shouldn't use conditionals inside useEffect.

So thanks again, and thanks SavagePixie for your post.