| 1 | --- |
| 2 | title: Avoid Boolean Prop Proliferation |
| 3 | impact: CRITICAL |
| 4 | impactDescription: prevents unmaintainable component variants |
| 5 | tags: composition, props, architecture |
| 6 | --- |
| 7 | |
| 8 | ## Avoid Boolean Prop Proliferation |
| 9 | |
| 10 | Don't add boolean props like `isThread`, `isEditing`, ` |
| 11 | component behavior. Each boolean doubles possible states and creates |
| 12 | unmaintainable conditional logic. Use composition instead. |
| 13 | |
| 14 | **Incorrect (boolean props create exponential complexity):** |
| 15 | |
| 16 | ```tsx |
| 17 | function Composer({ |
| 18 | onSubmit, |
| 19 | isThread, |
| 20 | channelId, |
| 21 | isDMThread, |
| 22 | dmId, |
| 23 | isEditing, |
| 24 | isForwarding, |
| 25 | }: Props) |
| 26 | return ( |
| 27 | <form> |
| 28 | <Header /> |
| 29 | <Input /> |
| 30 | {isDMThread ? ( |
| 31 | <AlsoSendToDMField id= |
| 32 | ) : isThread ? |
| 33 | <AlsoSendToChannelField id |
| 34 | ) : null} |
| 35 | {isEditing ? <EditActions |
| 36 | <Footer onSubmit= |
| 37 | </form> |
| 38 | ); |
| 39 | } |
| 40 | ``` |
| 41 | |
| 42 | **Correct (composition eliminates conditionals):** |
| 43 | |
| 44 | ```tsx |
| 45 | // Channel composer |
| 46 | function ChannelComposer() { |
| 47 | return ( |
| 48 | <Composer.Frame> |
| 49 | <Composer.Header /> |
| 50 | <Composer.Input /> |
| 51 | <Composer.Footer> |
| 52 | <Composer.Attachments /> |
| 53 | <Composer.Formatting /> |
| 54 | <Composer.Emojis /> |
| 55 | <Composer.Submit /> |
| 56 | </Composer.Footer> |
| 57 | </Composer.Frame> |
| 58 | ); |
| 59 | } |
| 60 | |
| 61 | // Thread composer - adds "also send to channel" field |
| 62 | function ThreadComposer({ channelId |
| 63 | return ( |
| 64 | <Composer.Frame> |
| 65 | <Composer.Header /> |
| 66 | <Composer.Input /> |
| 67 | <AlsoSendToChannelField id |
| 68 | <Composer.Footer> |
| 69 | <Composer.Formatting /> |
| 70 | <Composer.Emojis /> |
| 71 | <Composer.Submit /> |
| 72 | </Composer.Footer> |
| 73 | </Composer.Frame> |
| 74 | ); |
| 75 | } |
| 76 | |
| 77 | // Edit composer - different footer actions |
| 78 | function EditComposer() { |
| 79 | return ( |
| 80 | <Composer.Frame> |
| 81 | <Composer.Input /> |
| 82 | <Composer.Footer> |
| 83 | <Composer.Formatting /> |
| 84 | <Composer.Emojis /> |
| 85 | <Composer.CancelEdit /> |
| 86 | <Composer.SaveEdit /> |
| 87 | </Composer.Footer> |
| 88 | </Composer.Frame> |
| 89 | ); |
| 90 | } |
| 91 | ``` |
| 92 | |
| 93 | Each variant is explicit about what it renders. We can share internals without |
| 94 | sharing a single monolithic parent. |