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),
}

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.

Further reading

Problem with a question

Vue · Middle · question 43

Test yourself

Take the Vue · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz