/// import { ifElse, recipe, UI } from "commontools"; interface State { isActive: boolean; count: number; userType: string; score: number; hasPermission: boolean; isPremium: boolean; } export default recipe("ConditionalRendering", (state) => { return { [UI]: (

Basic Ternary

{state.isActive ? "Active" : "Inactive"} {state.hasPermission ? "Authorized" : "Denied"}

Ternary with Comparisons

{state.count > 10 ? "High" : "Low"} {state.score >= 90 ? "A" : state.score >= 80 ? "B" : "C"} {state.count === 0 ? "Empty" : state.count === 1 ? "Single" : "Multiple"}

Nested Ternary

{state.isActive ? (state.isPremium ? "Premium Active" : "Regular Active") : "Inactive"} {state.userType === "admin" ? "Admin" : state.userType === "user" ? "User" : "Guest"}

Complex Conditions

{state.isActive && state.hasPermission ? "Full Access" : "Limited Access"} {state.count > 0 && state.count < 10 ? "In Range" : "Out of Range"} {state.isPremium || state.score > 100 ? "Premium Features" : "Basic Features"}

IfElse Component

{ifElse( state.isActive,
User is active with {state.count} items
,
User is inactive
, )} {ifElse( state.count > 5,
  • Many items: {state.count}
,

Few items: {state.count}

, )}
), }; });