If Component
The <If> component provides declarative conditional rendering. Itβs a cleaner alternative to {condition && (<Component />)} patterns.
Basic Usage
import { If, Phase, Step, Claude } from "smithers-orchestrator";
<If condition={phase === "implement"}>
<Phase name="Implementation">
<Step name="implement">
<Claude>Implement the feature.</Claude>
</Step>
</Phase>
</If>
Condition to evaluate. Children render only when true.<If condition={status === "ready"}>
<Claude>Start the task.</Claude>
</If>
Content to render when condition is true.
Multi-Phase Workflow
import { If, SmithersProvider, Phase, Step, Claude, useSmithers } from "smithers-orchestrator";
import { useQueryValue } from "smithers-orchestrator/reactive-sqlite";
function Workflow({ db, executionId }) {
const phase = useQueryValue<string>(
db.db,
"SELECT value FROM state WHERE key = 'phase'"
) ?? "research";
const setPhase = (p: string) => db.state.set('phase', p);
return (
<SmithersProvider db={db} executionId={executionId} maxIterations={10}>
<If condition={phase === "research"}>
<Phase name="Research">
<Step name="research">
<Claude onFinished={() => setPhase("implement")}>
Research the codebase.
</Claude>
</Step>
</Phase>
</If>
<If condition={phase === "implement"}>
<Phase name="Implementation">
<Step name="implement">
<Claude onFinished={() => setPhase("test")}>
Implement the feature.
</Claude>
</Step>
</Phase>
</If>
<If condition={phase === "test"}>
<Phase name="Testing">
<Step name="test">
<Claude onFinished={() => setPhase("done")}>
Run tests.
</Claude>
</Step>
</Phase>
</If>
</SmithersProvider>
);
}
Benefits
- Cleaner JSX - No curly braces or parentheses clutter
- Better Readability - Intent is explicit
- Consistent Style - Matches JSX component patterns
- No Empty Renders - Returns
null when condition is false (same as &&)
Complex Conditions
<If condition={phase === "test" && testsEnabled}>
<Phase name="Testing">
<Step name="test">
<Claude>Run tests.</Claude>
</Step>
</Phase>
</If>