Custom Vars
As mentioned in the vars page, Reflex vars must be JSON serializable.
This means we can support any Python primitive types, as well as lists, dicts, and tuples. However, you can also create more complex var types by inheriting from rx.Base
or decorating them as dataclasses with @dataclasses.dataclass
.
Defining a Type
In this example, we will create a custom var type for storing translations.
Once defined, we can use it as a state var, and reference it from within a component.