Accessing previous value in a getter to only trigger effect if content of the value changed #3022
Unanswered
uli123abc
asked this question in
Help and Questions
Replies: 1 comment 1 reply
-
You cannot have a getter and a state property with the same name in pinia so this will break in other ways. What you are getting is just the state, there isn’t a previous value you can handle that with an extra value in state though |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In Vue 3.4+, the previous value of a getter can be accessed from a function parameter: https://vuejs.org/guide/essentials/computed#previous
When a getter returns an object or array, this allows for a pattern to compare the previous value with the newly computed value and to return the previous value if it didn't change: https://vuejs.org/guide/best-practices/performance.html#computed-stability
I would like to use a similar pattern for performance optimizations with Pinia getters, so that a getter that returns an array only triggers an effect if the content of the array changed.
Currently I am using the following with Pinia:
This works and solves my problem. However, I could not find any documentation about accessing the previous value through the
state.
like in this example. I wonder if that might break with future versions of Pinia and if there is a recommended solution?Beta Was this translation helpful? Give feedback.
All reactions