When working with record hooks, it is useful to be able to validate information using multiple fields. For example, say you require an email or user Id. You can use record hooks to compare the two fields, and if both are blank, you can mark the data with an error message on one or both fields to indicate to the user that one field or the other is required. In working with these two fields, you can reference
record.email
record.userId
Here's an example of the above usage:
It's key to note that while record hooks run both on
init
change
mode
registerRecordHooks
init
change
For the example here, we will add a different message onto the same field, one on
init
change
In the above example, when the file is dropped and the review stage begins, any record with an email would have red highlighting and display the message "On Init: Email in error state to show init" when the cell is hovered over. When any record on the field is updated, the email field for that record will then change to yellow highlighting and display the message "On Change: Email in warning state to show changed record" when hovered over.
In our guide for working with external data, we have an example and more details about this, but we think it is fair to also point out here the common uses and mistakes for using Data Hooks with external data.
In the above section, you can see how to split the record hooks based on
init
change
init
change
init
change
When considering Data Hooks best practices, it is important to re-iterate the order of which these hooks will process. In any import, field hooks will be run in the order that they are presented in the code (and will only run once), then record hooks on
init
change