State management
Use useStore()
to store the state of the component. The store's purpose is to:
- store the state of the component
- present the state as a proxy that can observe read/writes to the store
- serialize the state of the store into JSON on application pause.
- 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.