Defining Value Categories
Retomus lets you define custom value categories to handle internal or shared state more flexibly.
What is a Value Category?
A value category tells Retomus:
- How a value is created (e.g.,
useSharedValue
) - How to update it
- How to read its current state
Example: Shared Value
const CtxValueCategoryAsSharedValue: ValueCategory = {
id: 'sv',
use: initialValue => {
const sv = useSharedValue(initialValue);
return [
sv,
value => {
sv.value = value;
},
];
},
setterType: 'ref',
valuePropName: 'value',
};
Register it via valueCategories
:
const retomusConfig = createRetomusConfig({
valueCategories: [CtxValueCategoryAsSharedValue],
});
This allows you to use ctx.sv.yourValue
inside your machine logic.