<Branch> evaluates a boolean condition and executes exactly one of two branches: the then element when the condition is true, or the optional else element when the condition is false.
Import
Props
| Prop | Type | Default | Description |
|---|---|---|---|
if | boolean | (required) | The condition to evaluate. When true, the then branch executes. When false, the else branch executes (if provided). |
then | ReactElement | (required) | The element to render and execute when the condition is true. |
else | ReactElement | undefined | The element to render and execute when the condition is false. If omitted and the condition is false, nothing executes. |
skipIf | boolean | false | When true, the entire branch is skipped regardless of the condition. The component returns null. |
Basic usage
test task’s output has passed: true, the deploy task runs. Otherwise, notify-failure runs.
Without an else branch
Theelse prop is optional. When omitted and the condition is false, nothing executes for that branch.
Branching into complex sub-graphs
Each branch can contain any workflow element, not just a single<Task>. Use <Sequence>, <Parallel>, or other components to build complex sub-graphs:
Conditional skipping
UseskipIf to bypass the entire branch, regardless of the if condition:
skipIf is true, the component returns null and neither the then nor else branch is mounted.
How conditions are evaluated
Theif prop is evaluated at render time, when the JSX tree is constructed. This means the condition is based on data available in the context (ctx) at the point the workflow tree is built for that frame.
Because Smithers re-renders the workflow tree each frame, branch conditions can depend on the outputs of previously completed tasks:
ctx.outputMaybe() instead of ctx.output() when the upstream task may not have completed yet (e.g., on the first render frame before the task runs).
Rendering
Internally,<Branch> renders the chosen child (then or else) wrapped in a <smithers:branch> host element. Only the selected branch’s tasks are mounted into the execution plan. The non-selected branch’s tasks are not present in the task graph.
Notes
- Only one branch executes per render frame. The non-selected branch is not mounted.
thenandelseaccept a singleReactElementeach. Wrap multiple elements in<Sequence>or<Parallel>if you need more than one child per branch.- Branch conditions are re-evaluated on each render frame, which is how Smithers supports data-dependent control flow.