State management

Use useStore() to store the state of the component. The store's purpose is to:

  1. store the state of the component
  2. present the state as a proxy that can observe read/writes to the store
  3. serialize the state of the store into JSON on application pause.
  4. observe which properties of the store are used in a component template and create subscriptions to the store. The subscriptions are then used to automatically update the component template if a store changes.

Stores are declared inside the component's function using the useStore() function. Wrap the github assignment in the useStore(...) function call to create a store.

NOTE In this example, the store never changes. Therefore there is no way to observe automatic template re-rendering. In the next example, we will add a listener to the <input> to demonstrate automatic template re-rendering.

Edit Tutorial