title: Vuex - When to use getters and when to use state
body: <p>I have a hard time figuring out when to use a getter or a state for best performance.</p>
  
  <p>I will list some scenarios that you are welcome to comment on:</p>
  
  <p><strong>Scenario 1 - Getters VS state in actions and getters</strong></p>
  
  <p>In an action or getter, if you use a list of products multiple times to find a result would you then use getters.products or state.products?</p>
  
  <p>Also, if you needed to use the products 10 times in the same function, would you call getters.products or state.products 10 times or would you assign the products to a variable at the beginning and then use that 10 
  times? Are there any perfomance gain in any over the others?</p>
  
  <p><strong>Scenario 2 - Getters returning a function</strong></p>
  
  <p>In the Vuex documentation it states that returning a function in a getter will not cache the result of that function. So having a getter for sorting a list of 1000 products would be bad, right? Like:</p>
  
  <pre><code>const getters = {
    sortedProducts: state =&gt; {
      return state.products.sort(a, b =&gt; {
        ...
      })
    }
  }
  </code></pre>
  
  <p>So when ever a product is updated, which may or may not alter the sorting, then it would do the entire calculation once again, or?</p>
  
  <p>Would it be better to have a state instead that is manually updated by an action and mutation?</p>
  
  <p>Generally, would it ever make sense to have getters returning functions that has to do with large amount of data?</p>