Skip to content

Commit 16ae994

Browse files
committed
react demo.
1 parent adfd055 commit 16ae994

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

demos/react-app/src/playground/Playground.tsx

+21-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState } from 'react';
1+
import { useEffect, useMemo, useState } from 'react';
22
import { ObjectCloner, Step, StepsConfiguration, ToolboxConfiguration, ValidatorConfiguration } from 'sequential-workflow-designer';
33
import { SequentialWorkflowDesigner, wrapDefinition } from 'sequential-workflow-designer-react';
44
import { RootEditor } from './RootEditor';
@@ -14,21 +14,28 @@ const startDefinition: WorkflowDefinition = {
1414
sequence: [createTaskStep(), createSwitchStep()]
1515
};
1616

17-
const toolboxConfiguration: ToolboxConfiguration = {
18-
groups: [{ name: 'Steps', steps: [createTaskStep(), createSwitchStep()] }]
19-
};
20-
21-
const stepsConfiguration: StepsConfiguration = {
22-
iconUrlProvider: () => null
23-
};
24-
25-
const validatorConfiguration: ValidatorConfiguration = {
26-
step: (step: Step) => Boolean(step.name),
27-
root: (definition: WorkflowDefinition) => Boolean(definition.properties.alfa)
28-
};
29-
3017
export function Playground() {
3118
const controller = useSequentialWorkflowDesignerController();
19+
const toolboxConfiguration: ToolboxConfiguration = useMemo(
20+
() => ({
21+
groups: [{ name: 'Steps', steps: [createTaskStep(), createSwitchStep()] }]
22+
}),
23+
[]
24+
);
25+
const stepsConfiguration: StepsConfiguration = useMemo(
26+
() => ({
27+
iconUrlProvider: () => null
28+
}),
29+
[]
30+
);
31+
const validatorConfiguration: ValidatorConfiguration = useMemo(
32+
() => ({
33+
step: (step: Step) => Boolean(step.name),
34+
root: (definition: WorkflowDefinition) => Boolean(definition.properties.alfa)
35+
}),
36+
[]
37+
);
38+
3239
const [isVisible, setIsVisible] = useState(true);
3340
const [isToolboxCollapsed, setIsToolboxCollapsed] = useState(false);
3441
const [isEditorCollapsed, setIsEditorCollapsed] = useState(false);

react/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ const [definition, setDefinition] = useState(() => wrapDefinition(startDefinitio
5454
Configure the designer.
5555

5656
```ts
57-
const toolboxConfiguration: ToolboxConfiguration = { /* ... */ };
58-
const stepsConfiguration: StepsConfiguration = { /* ... */ };
59-
const validatorConfiguration: ValidatorConfiguration = { /* ... */ };
57+
const toolboxConfiguration: ToolboxConfiguration = useMemo(() => ({ /* ... */ }), []);
58+
const stepsConfiguration: StepsConfiguration = useMemo(() => ({ /* ... */ }), []);
59+
const validatorConfiguration: ValidatorConfiguration = useMemo(() => ({ /* ... */ }), []);
6060
```
6161

6262
Create the root editor component:

0 commit comments

Comments
 (0)