Vue · Middle · Question 43 of 75
Why isn't this Pinia getter cached?
getters: {
byId: (state) => (id: number) => state.items.find((i) => i.id === id),
}- ✓Correct answer: It returns a function; the function is cached, but each call with an argument runs the search again
- 2Getters are never cached in Pinia
- 3Getters with arrow functions can't access state
Explanation
Getters behave like computed properties. For frequent lookups by id, keep a computed map (Map or object keyed by id) and read from it.