nanostores / query

⚡️ Powerful data fetching library for Nano Stores. TS/JS. Framework agnostic.
MIT License
216 stars 10 forks source link

When to use mutations (and not plain functions) #31

Closed dkzlv closed 5 months ago

dkzlv commented 7 months ago

This may be another good topic for documentation, but broadly speaking you want to use mutations in 2 major cases:

  1. you use those loading and error values in the store. Basically, it runs a promise for you and gives some sugar on top of it.
  2. you want to optimistically update cache beforehand (mutations give a good sugar for that as well).

If you don't need either, just go with a good ol' function! Mutations don't really give you any added benefit