FRONTENDO
Emberhold Forge
0
0
Vue.js · Vue.js State Management
New technique

Where does state live?

Keep your tools close to where you use them. Only the big anvil belongs in the middle of the forge.

State is the data that changes while your app runs: what's in the cart, which hall is open, whether a menu is shown.

Keep it as local as you can, and share it only as widely as needed. State that the whole app can change needs one clear home, or you'll never know who changed it.

  • Local state → a ref inside one component.
  • Parent and child → props down, events up.
  • A deep tree of components → provide / inject.
  • Shared across the whole app → a Pinia store.