State
Add a count field with an initial value of 0. f.number(0) describes a numeric field; self.model.count accesses its store on the displayed instance.
Step 1 / 2
export const CounterModel = staticModel({
data: { count: f.number(0) },
});
Add a numeric field with an initial value of zero.
f.number(0)field declarationcountstore on the instancef.number(0) → count
Import f from @virentia/core/models. Pass the store itself to JSX: {self.model.count}. The renderer binds the button's text to it.
Do not substitute count.value: that reads a number when view is created, rather than establishing a binding. Actions will read and write .value in the next chapter.
Change the initial value to 10. The button now shows 10, but clicking does nothing yet. Next, add an action.