How to initialize and wrap a workflow definition
mainBefore passing a workflow definition to the designer, it must be wrapped using the wrapDefinition function. This ensures the definition is in the format expected by the designer's internal state management. It is recommended to use useState to manage the wrapped definition and useMemo for configuration objects to prevent unnecessary re-renders.
import { Definition, ToolboxConfiguration, StepsConfiguration, ValidatorConfiguration } from 'sequential-workflow-designer';
import { SequentialWorkflowDesigner, wrapDefinition, useRootEditor, useStepEditor } from 'sequential-workflow-designer-react';
// 1. Define the raw definition
const startDefinition: Definition = { /* ... */ };
// 2. Wrap it and store in state
const [definition, setDefinition] = useState(() => wrapDefinition(startDefinition));
// 3. Memoize configurations
const toolboxConfiguration: ToolboxConfiguration = useMemo(() => ({ /* ... */ }), []);
const stepsConfiguration: StepsConfiguration = useMemo(() => ({ /* ... */ }), []);
const validatorConfiguration: ValidatorConfiguration = useMemo(() => ({ /* ... */ }), []);