Reactive props
Last updated
Last updated
This is a highly experimental technology and it may change, or be removed in the future. Follow the release notes to stay in tune.
Reactive prop - is a field's prop, which value is resolved automatically using the live subscriptions system. The latter allows to subscribe to props changes of another fields, and re-evaluate the reactive prop's resolver whenever the referenced props update.
This is a generic concept implemented in several features of React Advanced Form. Those are listed below in this section. Each feature may utilize this concept in a different way, although the interface strives to be unified.
Below, there is a list of behaviors applicable to reactive props, regardless of where they are used. For consistency's sake, interface is used in these examples.
It is possible to reference multiple fields within a single reactive prop resolver function:
This will create two observers, respectively, and each change of the referenced props will trigger re-evaluataion of that required
resolver function.
Reactive prop resolver can also reference fields which haven't mounted yet at the moment when the resolver function is declared. In that case a direct subscription cannot be created. Instead, a delegated subscription is created.
The purpose of the delegated subscription is to listen for the field registration event and re-evaluate the resolver function after the mounting occurs.
Delegated subscription behaves the following way:
Listens to the event when the referenced field becomes registered.
Analyzes the resolver function once more, gathering the references props of the newly registered referenced field.
Creates a subscription for the changes of the referenced props list.
Removes the delegated subscription.
To illustrate this, consider the next scenario:
By the time fielTwo.props.required
reactive prop is evaluated, the referenced fieldThree
doesn't exist yet. Once the referenced field has been mounted, the resolver function (fieldTwo.props.required
) is re-evaluated, and the value of required
prop is updated according to the resolver logic (to true
in the example above).
To create a reactive field prop simply pass a function as its value, and use the exposed get
method to reference props of another fields.
Note: At the moment reactive field props are supported only for the
required
prop.
Whenever another field's prop is referenced using the get
method, a live subscription for that referenced prop is created.
Reactive props resolver is never assigned as a value of the reactive prop. Instead, it is copied and executed whenever the referenced prop updates, consequentially updating the prop, which is connected to the resolver.
Note: It is possible to reference any props from the (i.e. value
, valid
, validSync
, and many more).
The concept of reactive props is applicable to synchronous validation rules as well. Just as with the , whenever another field's prop is referenced within a synchronous validation rule declaration, the latter is re-evaluated each time the referenced props update.