You can create multi-step logic in a Flow using the s.Condition structure. A condition block evaluates a predicate function (if) and branches the form flow into either a then array or an else array based on the result.
if: A function that receives the current form state and returns a boolean.then: An array of steps to execute if the condition is true. This typically includes a form step followed by a return step to merge the new data into the main state.else: An array of steps to execute if the condition is false.return: A step used within a branch to map the local branch data back into the global form schema.
This pattern allows for complex, nested logic where the final data object is a composition of the paths taken through the flow.
import type { Flow, s } from "@formity/react";
export const conditionFlow: Flow<ConditionSchema> = [
{
form: {
fields: () => ({ softwareDeveloper: [true, []] }),
render: ({ fields, ...rest }) => (
<Form ... />
),
},
},
{
condition: {
if: ({ softwareDeveloper }) => softwareDeveloper,
then: [
{
form: {
fields: () => ({ languages: [[], []] }),
render: ({ fields, ...rest }) => (
<Form ... />
),
},
},
{
return: ({ languages }) => ({
softwareDeveloper: true,
languages,
}),
},
],
else: [
{
form: {
fields: () => ({ interested: ["maybe", []] }),
render: ({ fields, ...rest }) => (
<Form ... />
),
},
},
{
return: ({ interested }) => ({
softwareDeveloper: false,
interested,
}),
},
],
},
},
];