SJSF provides two types of methods to interact with the FormState: Queries and Commands. Understanding the difference is critical for managing reactivity in Svelte.
Queries (@query)
Queries are used to read data from the form state. When a query is called, the reactive variables it accesses will be tracked by Svelte's reactivity system.
Common Queries:
getFieldErrors, getErrors, hasErrors: Access validation state.getValueSnapshot: Get the current value.retrieveSchema, retrieveUiSchema: Access schema definitions.getId, getIdByPath: Retrieve unique identifiers for fields.
Commands (@command)
Commands are used to modify the form state. When a command is called, the accessed variables will not be tracked by the reactivity system, preventing infinite loops or unintended side effects during state transitions.
Common Commands:
setValue: Update a field's value.validateField: Trigger validation for a specific field.updateErrors, updateFieldErrors: Manually update error states.setFieldStateByPath: Update field state directly.