docs/solutions/style.md
Reference: @docs/solutions/style.md, @www/content/docs/server/http.mdx
Write verbose, educational documentation. Guide the reader step by step. Advanced / low-level documentation should be written in a last section ## API Reference (if any).
Bad: Here's the code.
const form = useForm({ resolver: zodResolver(schema) });
Good: Next, we'll use the useForm hook from React Hook Form to create our form instance. We'll also add the Zod resolver to validate the form data.
const form = useForm({ resolver: zodResolver(schema) });
Bad: Add accessibilityLayer to your chart.
Good: You can turn on the accessibilityLayer prop to add an accessible layer to your chart. This prop adds keyboard access and screen reader support to your charts.
Start simple, add complexity. Use transitions:
ChartTooltip component."End sections with accomplishment:
Connect ideas naturally:
Use callouts for critical information:
<Callout icon={<InfoIcon />}>
**Note:** We're returning `values` for error cases. This is because we want to keep the user submitted values in the form state.
</Callout>
<Callout icon={<InfoIcon />}>
**Important:** Remember to set a `min-h-[VALUE]` on the `ChartContainer` component. This is required for the chart to be responsive.
</Callout>
Organize options, modes, props clearly:
| Mode | Description |
| ------------ | ---------------------------------------- |
| `"onChange"` | Validation triggers on every change. |
| `"onBlur"` | Validation triggers on blur. |
| `"onSubmit"` | Validation triggers on submit (default). |
Bad:
// Your validation logic here
Good:
const result = formSchema.safeParse(values);
if (!result.success) {
return {
values,
success: false,
errors: result.error.flatten().fieldErrors,
};
}
Use {line-numbers} to focus attention:
```tsx showLineNumbers {17-23}
// Lines 17-23 are highlighted
```
### 10. Use Steps for Multi-Part Processes
```md
<Steps>
<Step>Import the `CartesianGrid` component.</Step>
```tsx
import { Bar, BarChart, CartesianGrid } from "recharts"
<Step>Add the CartesianGrid component to your chart.</Step>
<BarChart>
<CartesianGrid vertical={false} />
</BarChart>
Flexible, but typically includes:
import { InfoIcon } from "lucide-react"Explain what the reader will learn:
In this guide, we will take a look at building forms with React Hook Form. We'll cover building forms with the `<Field />` component, adding schema validation using Zod, error handling, accessibility, and more.
Or start with what you'll build:
We are going to build the following form. It has a simple text input and a textarea. On submit, we'll validate the form data and display any errors.
Explain methodology with bullets + comparison table:
## Approach
This form leverages React Hook Form for performant, flexible form handling. We'll build our form using the `<Field />` component, which gives you **complete flexibility over the markup and styling**.
- Uses React Hook Form's `useForm` hook for form state management.
- `<Controller />` component for controlled inputs.
- Client-side validation using Zod with `zodResolver`.
| Use Case | Approach |
| --------- | -------------------- |
| REST APIs | cRPC HTTP Router ✅ |
| Real-time | Queries/Mutations ✅ |
| Webhooks | Traditional HTTP |
Use H3 for steps within a feature. Start with a guiding sentence:
### Create a form schema
We'll start by defining the shape of our form using a Zod schema.
### Add Tooltip
So far we've only used components from Recharts. They look great out of the box thanks to some customization in the `chart` component.
To add a tooltip, we'll use the custom `ChartTooltip` and `ChartTooltipContent` components.
Always include:
showLineNumbers for multi-line codetitle="filename.tsx" for file context{10-21} for highlighting important lines```tsx showLineNumbers title="form.tsx" {17-23}
// Code with lines 17-23 highlighted
```
## Tone
- **Educational** - Teach, don't just document
- **Conversational** - "Let's", "We'll", "You can"
- **Encouraging** - "Easy, right?", "That's it."
- **Practical** - Real examples, real gotchas
- **Clear** - One concept at a time
## Anti-Patterns
❌ Walls of code without explanation
❌ Placeholder comments like `// Your logic here`
❌ Jumping to advanced concepts without building up
❌ Missing the "why" behind choices
❌ Dry, reference-style prose when tutorial-style fits better
❌ Forgetting to celebrate completion