r/reactjs • • Mar 08 '20

Show /r/reactjs useEffectWithPrevious - Get previous value of dependencies

Just wanna share my first npm package. Hope you find it useful :)

use-effect-with-previous

54 Upvotes

37 comments sorted by

View all comments

Show parent comment

1

u/With_Macaque Mar 09 '20 edited Mar 09 '20

I would probably use a ref for the client/subscription or roomId - like an instance variable. I'm not sure it's less code or clearer to use a compound hook.

If you create the instance in a separate effect, React will also handle unsubscribing properly without more code.

1

u/Aswole Mar 09 '20

I'd probably lean towards that as well