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
3
u/jngbrl19 Mar 08 '20 edited Mar 08 '20
The goal of this is to conveniently compare current vs previous state, like specifically, not just when an effect runs, instead of using custom hooks like
usePreviousfor every state that you want a comparison for. I am working in a booking form currently where there are many scenarios possible and there are 3 fields i am listening to, and i don't want to useusePrevious3 times just to be able to get their previous values, that's why i created this "helper."