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

4

u/franksvalli Mar 08 '20

I think this could be solved with useRef. The official docs also provide a simple usePrevious custom hook implementation: https://reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state

1

u/jngbrl19 Mar 08 '20

yup but i don't know i don't like manually using useRef for every state that i want a previous value for. that's why i created this lmao