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