Skip to content

Commit 68320cc

Browse files
docs: Fix control prop usage in documentation examples
- Remove unnecessary control prop from component examples - Update to use FormProvider pattern as per Cursor Rules - Components use useFormContext() internally, no need to pass control - Add proper FormProvider wrapper in examples - Update both Basic Usage and Medusa Integration examples Fixes the documentation to reflect that Medusa Forms components have built-in hooks and don't require the control prop to be passed explicitly.
1 parent d4e739d commit 68320cc

1 file changed

Lines changed: 38 additions & 37 deletions

File tree

apps/docs/src/0.1 Hello World (start here).mdx

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,32 @@ yarn add @lambdacurry/medusa-forms
4444
### Basic Usage
4545

4646
```tsx
47-
import { useForm } from 'react-hook-form';
47+
import { useForm, FormProvider } from 'react-hook-form';
4848
import { ControlledInput, ControlledSelect } from '@lambdacurry/medusa-forms';
4949

5050
function MyForm() {
51-
const { control, handleSubmit } = useForm();
51+
const methods = useForm();
5252

5353
return (
54-
<form onSubmit={handleSubmit(console.log)}>
55-
<ControlledInput
56-
control={control}
57-
name="title"
58-
label="Product Title"
59-
placeholder="Enter product title..."
60-
rules={{ required: 'Title is required' }}
61-
/>
62-
63-
<ControlledSelect
64-
control={control}
65-
name="status"
66-
label="Status"
67-
options={[
68-
{ label: 'Draft', value: 'draft' },
69-
{ label: 'Published', value: 'published' }
70-
]}
71-
/>
72-
</form>
54+
<FormProvider {...methods}>
55+
<form onSubmit={methods.handleSubmit(console.log)}>
56+
<ControlledInput
57+
name="title"
58+
label="Product Title"
59+
placeholder="Enter product title..."
60+
rules={{ required: 'Title is required' }}
61+
/>
62+
63+
<ControlledSelect
64+
name="status"
65+
label="Status"
66+
options={[
67+
{ label: 'Draft', value: 'draft' },
68+
{ label: 'Published', value: 'published' }
69+
]}
70+
/>
71+
</form>
72+
</FormProvider>
7373
);
7474
}
7575
```
@@ -80,25 +80,27 @@ These components are designed to work perfectly in Medusa Admin interfaces:
8080

8181
```tsx
8282
import { RouteConfig } from "@medusajs/admin"
83+
import { FormProvider, useForm } from "react-hook-form"
8384
import { ControlledInput, ControlledCurrencyInput } from "@lambdacurry/medusa-forms"
8485

8586
const ProductForm = () => {
86-
// Your Medusa admin form logic here
87+
const methods = useForm();
88+
8789
return (
88-
<div>
89-
<ControlledInput
90-
control={control}
91-
name="title"
92-
label="Product Title"
93-
/>
94-
<ControlledCurrencyInput
95-
control={control}
96-
name="price"
97-
label="Price"
98-
symbol="$"
99-
code="USD"
100-
/>
101-
</div>
90+
<FormProvider {...methods}>
91+
<form onSubmit={methods.handleSubmit(console.log)}>
92+
<ControlledInput
93+
name="title"
94+
label="Product Title"
95+
/>
96+
<ControlledCurrencyInput
97+
name="price"
98+
label="Price"
99+
symbol="$"
100+
code="USD"
101+
/>
102+
</form>
103+
</FormProvider>
102104
)
103105
}
104106

@@ -136,4 +138,3 @@ Check out our **Form Integration Examples** story to see complete working forms
136138
---
137139

138140
**Ready to build better forms?** Start exploring the components in the sidebar! 👈
139-

0 commit comments

Comments
 (0)