Show Alternatives
Compare different approaches to solve the same problem.
Usage
/learn:alternatives # Compare approaches for current code
/learn:alternatives auth # Compare authentication methods
/learn:alternatives state # Compare state management options
/learn:alternatives --detailed # Include code examples for each
Instructions
- Identify the problem being solved (from context or argument)
- Present 3-5 alternative approaches
- For each approach, explain:
- What it is (one sentence)
- When to use it
- Trade-offs (pros/cons)
- Provide a recommendation based on context
- Optionally show code examples for top choices
Response Format
## Problem: [What we're trying to solve]
### Approach 1: [Name]
**What**: [One-sentence description]
**When to use**:
- [Scenario 1]
- [Scenario 2]
**Pros**: [List]
**Cons**: [List]
---
### Approach 2: [Name]
...
---
## Comparison Table
| Criteria | Approach 1 | Approach 2 | Approach 3 |
|----------|------------|------------|------------|
| Complexity | Low | Medium | High |
| Performance | ★★☆ | ★★★ | ★★☆ |
| Bundle size | Small | Medium | Large |
| Learning curve | Easy | Medium | Steep |
## Recommendation
**For your case**: [Recommended approach] because [reason based on context]
**Consider instead if**: [Alternative scenarios]
Comparison Criteria
Standard criteria to evaluate (adjust based on problem):
| Criteria |
Description |
| Complexity |
How hard to implement and maintain |
| Performance |
Runtime speed, memory usage |
| Bundle size |
Impact on frontend bundle |
| Learning curve |
Time to understand and use correctly |
| Flexibility |
Ease of extending or modifying |
| Community |
Documentation, ecosystem, support |
| Testing |
How easy to test |
| Type safety |
TypeScript support quality |
Depth Modes
Default
- 3-4 alternatives
- Brief description each
- Comparison table
- Recommendation
--detailed
- 4-5 alternatives
- Code example for each
- Detailed trade-offs
- Migration considerations
- Real-world case studies
--quick
- 2-3 alternatives
- One-line each
- Quick recommendation
Example Session
User: I'm using useState for form state. /learn:alternatives
Claude: ## Problem: Managing Form State in React
### Approach 1: Multiple useState
**What**: Separate useState for each field
**When to use**:
- Simple forms (< 5 fields)
- No complex validation
- No cross-field dependencies
**Pros**: Simple, no dependencies, easy to understand
**Cons**: Verbose with many fields, scattered state
---
### Approach 2: Single useState with Object
**What**: One useState holding all fields as object
**When to use**:
- Medium forms (5-10 fields)
- Need to reset entire form
- Want cleaner code
**Pros**: Grouped state, easy reset, cleaner
**Cons**: Need spread operator, can cause unnecessary re-renders
---
### Approach 3: useReducer
**What**: Reducer pattern for complex state transitions
**When to use**:
- Complex validation logic
- Multi-step forms
- Undo/redo functionality
**Pros**: Predictable updates, handles complex logic, testable
**Cons**: More boilerplate, learning curve
---
### Approach 4: Form Library (React Hook Form, Formik)
**What**: Dedicated form state management library
**When to use**:
- Large forms (10+ fields)
- Complex validation (async, cross-field)
- Performance critical (many fields)
**Pros**: Optimized re-renders, validation built-in, less code
**Cons**: Dependency, learning curve, bundle size
---
## Comparison Table
| Criteria | useState | useReducer | React Hook Form |
|----------|----------|------------|-----------------|
| Complexity | Low | Medium | Medium |
| Performance | ★★☆ | ★★☆ | ★★★ |
| Bundle size | 0kb | 0kb | ~8kb |
| Validation | Manual | Manual | Built-in |
| Best for | Simple | Complex logic | Large forms |
## Recommendation
**For your case**: If this is a simple login/contact form, stick with **useState**. If you're building a multi-step checkout or admin form, consider **React Hook Form** for the validation and performance benefits.
**Consider useReducer if**: You need undo/redo, complex state machines, or want reducer-style testing.
Common Alternative Comparisons
| Topic |
Typical Alternatives |
| State |
useState, useReducer, Zustand, Redux, Jotai |
| Styling |
CSS Modules, Tailwind, styled-components, CSS-in-JS |
| Data fetching |
fetch, axios, React Query, SWR |
| Forms |
useState, React Hook Form, Formik |
| Auth |
JWT, sessions, OAuth, magic links |
| API design |
REST, GraphQL, tRPC, gRPC |
| Testing |
Jest, Vitest, Testing Library, Cypress |
| Databases |
PostgreSQL, MySQL, MongoDB, SQLite |
$ARGUMENTS
1---2name: learn-alternatives3description: Compare different approaches to solve the same problem4---5
6# Show Alternatives
7
8Compare different approaches to solve the same problem.
9
10## Usage
11
12```
13/learn:alternatives # Compare approaches for current code
14/learn:alternatives auth # Compare authentication methods
15/learn:alternatives state # Compare state management options
16/learn:alternatives --detailed # Include code examples for each
17```
18
19## Instructions
20
211. Identify the **problem being solved** (from context or argument)
222. Present **3-5 alternative approaches**
233. For each approach, explain:
24 - What it is (one sentence)
25 - When to use it
26 - Trade-offs (pros/cons)
274. Provide a **recommendation** based on context
285. Optionally show code examples for top choices
29
30## Response Format
31
32```markdown
33## Problem: [What we're trying to solve]
34
35### Approach 1: [Name]
36
37**What**: [One-sentence description]
38
39**When to use**:
40- [Scenario 1]
41- [Scenario 2]
42
43**Pros**: [List]
44**Cons**: [List]
45
46---
47
48### Approach 2: [Name]
49...
50
51---
52
53## Comparison Table
54
55| Criteria | Approach 1 | Approach 2 | Approach 3 |
56|----------|------------|------------|------------|
57| Complexity | Low | Medium | High |
58| Performance | ★★☆ | ★★★ | ★★☆ |
59| Bundle size | Small | Medium | Large |
60| Learning curve | Easy | Medium | Steep |
61
62## Recommendation
63
64**For your case**: [Recommended approach] because [reason based on context]
65
66**Consider instead if**: [Alternative scenarios]
67```
68
69## Comparison Criteria
70
71Standard criteria to evaluate (adjust based on problem):
72
73| Criteria | Description |
74|----------|-------------|
75| **Complexity** | How hard to implement and maintain |
76| **Performance** | Runtime speed, memory usage |
77| **Bundle size** | Impact on frontend bundle |
78| **Learning curve** | Time to understand and use correctly |
79| **Flexibility** | Ease of extending or modifying |
80| **Community** | Documentation, ecosystem, support |
81| **Testing** | How easy to test |
82| **Type safety** | TypeScript support quality |
83
84## Depth Modes
85
86### Default
87- 3-4 alternatives
88- Brief description each
89- Comparison table
90- Recommendation
91
92### `--detailed`
93- 4-5 alternatives
94- Code example for each
95- Detailed trade-offs
96- Migration considerations
97- Real-world case studies
98
99### `--quick`
100- 2-3 alternatives
101- One-line each
102- Quick recommendation
103
104## Example Session
105
106```
107User: I'm using useState for form state. /learn:alternatives
108
109Claude: ## Problem: Managing Form State in React
110
111### Approach 1: Multiple useState
112
113**What**: Separate useState for each field
114
115**When to use**:
116- Simple forms (< 5 fields)
117- No complex validation
118- No cross-field dependencies
119
120**Pros**: Simple, no dependencies, easy to understand
121**Cons**: Verbose with many fields, scattered state
122
123---
124
125### Approach 2: Single useState with Object
126
127**What**: One useState holding all fields as object
128
129**When to use**:
130- Medium forms (5-10 fields)
131- Need to reset entire form
132- Want cleaner code
133
134**Pros**: Grouped state, easy reset, cleaner
135**Cons**: Need spread operator, can cause unnecessary re-renders
136
137---
138
139### Approach 3: useReducer
140
141**What**: Reducer pattern for complex state transitions
142
143**When to use**:
144- Complex validation logic
145- Multi-step forms
146- Undo/redo functionality
147
148**Pros**: Predictable updates, handles complex logic, testable
149**Cons**: More boilerplate, learning curve
150
151---
152
153### Approach 4: Form Library (React Hook Form, Formik)
154
155**What**: Dedicated form state management library
156
157**When to use**:
158- Large forms (10+ fields)
159- Complex validation (async, cross-field)
160- Performance critical (many fields)
161
162**Pros**: Optimized re-renders, validation built-in, less code
163**Cons**: Dependency, learning curve, bundle size
164
165---
166
167## Comparison Table
168
169| Criteria | useState | useReducer | React Hook Form |
170|----------|----------|------------|-----------------|
171| Complexity | Low | Medium | Medium |
172| Performance | ★★☆ | ★★☆ | ★★★ |
173| Bundle size | 0kb | 0kb | ~8kb |
174| Validation | Manual | Manual | Built-in |
175| Best for | Simple | Complex logic | Large forms |
176
177## Recommendation
178
179**For your case**: If this is a simple login/contact form, stick with **useState**. If you're building a multi-step checkout or admin form, consider **React Hook Form** for the validation and performance benefits.
180
181**Consider useReducer if**: You need undo/redo, complex state machines, or want reducer-style testing.
182```
183
184## Common Alternative Comparisons
185
186| Topic | Typical Alternatives |
187|-------|---------------------|
188| **State** | useState, useReducer, Zustand, Redux, Jotai |
189| **Styling** | CSS Modules, Tailwind, styled-components, CSS-in-JS |
190| **Data fetching** | fetch, axios, React Query, SWR |
191| **Forms** | useState, React Hook Form, Formik |
192| **Auth** | JWT, sessions, OAuth, magic links |
193| **API design** | REST, GraphQL, tRPC, gRPC |
194| **Testing** | Jest, Vitest, Testing Library, Cypress |
195| **Databases** | PostgreSQL, MySQL, MongoDB, SQLite |
196
197$ARGUMENTS