Props
Reuse the component for several counters. Add a label field and give each counter its own name and initial count.
Step 1 / 2
export const CounterModel = staticModel({
data: {
count: f.number(0),
label: f.string("Counter"),
},
// setup is unchanged
});
Add label to the model's inputs. Keep the existing setup.
labelconstructor inputCounterModellabel storelabel → CounterModel
Replace the single <Counter /> in main with both counters:
tsx
render(() => <>
<Counter label="Coffee" count={2} />
<Counter label="Tea" count={5} />
</>, container, { scope: appScope });label and count are model inputs. These plain strings and numbers provide initial instance values. View reads the instance's stores through self.model.
Click Coffee. Tea stays unchanged: each display has its own instance, even though both share the CounterModel definition.
For live prop sources, see reactive inputs.