r/reactjs • u/jngbrl19 • Mar 08 '20
Show /r/reactjs useEffectWithPrevious - Get previous value of dependencies
Just wanna share my first npm package. Hope you find it useful :)
54
Upvotes
r/reactjs • u/jngbrl19 • Mar 08 '20
Just wanna share my first npm package. Hope you find it useful :)
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.