Skip to content

Commit db1c6de

Browse files
committed
Update react components docs
1 parent 716fe5b commit db1c6de

File tree

3 files changed

+41
-41
lines changed

3 files changed

+41
-41
lines changed

core-concepts/react-components.mdx

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
11
---
2-
title: "React Components"
3-
description: "Learn how to use React components"
2+
title: "React"
3+
description: "Build interactive and reusable elements with React components"
44
icon: "react"
55
---
66

77
import { Counter } from "/snippets/counter.mdx";
88
import { ColorGenerator } from "/snippets/color-generator.mdx";
99

10-
Create interactive examples and dynamic content in your documentation using familiar [React hooks](https://react.dev/reference/react/hooks).
10+
[React components](https://react.dev) are a powerful way to create interactive and reusable elements in your documentation.
1111

12-
<Note>
13-
No imports needed! All standard React hooks are automatically available in your MDX files.
14-
</Note>
12+
You can use React directly in your MDX files without any additional setup.
1513

16-
## Available Hooks
1714

18-
You can use all standard React hooks in your documentation, such as `useState`, `useEffect`, and other [React hooks](https://react.dev/reference/react/hooks).
15+
## Using React Components
1916

20-
## Interactive Examples
17+
You can build components directly in your MDX files using [React hooks](https://react.dev/reference/react/hooks).
2118

22-
### Creating Components Directly in MDX
19+
### Basic Example
2320

24-
Create a component directly in your MDX file using React hooks to build interactive elements that respond to user actions:
25-
26-
*A basic counter component created with `useState` hook*
27-
28-
<Counter />
21+
Here's a basic example of a counter component:
2922

3023
```jsx
3124
export const Counter = () => {
@@ -40,23 +33,21 @@ export const Counter = () => {
4033
</div>
4134
);
4235
}
43-
44-
<Counter />
4536
```
4637

47-
### Importing Components from Snippet Files
48-
49-
Import snippets into your MDX files to create reusable interactive components. Store snippets in the `snippets` folder for better organization. Learn more in the [reusable snippets documentation](/reusable-snippets).
38+
The `Counter` component can then be used in your MDX files like this:
5039

51-
*Interactive HSL color generator created with multiple React hooks*
40+
```jsx
41+
<Counter />
42+
```
5243

53-
<ColorGenerator />
44+
And the component will be rendered as a React component in the MDX file.
5445

55-
## Using React Hooks
46+
<Counter />
5647

57-
### Create a snippet file
48+
### Complex Example
5849

59-
Create a new file in the `snippets` folder with your component code.
50+
You can also build much more complex components. Here's an example of a color generator component that uses multiple React hooks:
6051

6152
```jsx /snippets/color-generator.mdx [expandable]
6253
export const ColorGenerator = () => {
@@ -86,9 +77,7 @@ export const ColorGenerator = () => {
8677
}
8778

8879
return (
89-
<div className="p-4 border dark:border-zinc-950/80 rounded-xl bg-white dark:bg-zinc-950/80 shadow-sm">
90-
<span className="text-xl mb-4 font-semibold text-zinc-950/80 dark:text-white/80">HSL Color Generator</span>
91-
80+
<div className="p-4 border dark:border-zinc-950/80 rounded-xl not-prose">
9281
<div className="space-y-4">
9382
<div className="space-y-2">
9483
<label className="block text-sm text-zinc-950/70 dark:text-white/70">
@@ -173,23 +162,36 @@ export const ColorGenerator = () => {
173162
}
174163
```
175164

176-
### Import the snippet
165+
The above component can then be used in your MDX files like this:
177166

178-
Add an import statement at the top of your MDX file:
167+
```jsx
168+
<ColorGenerator />
169+
```
170+
171+
And the component will be rendered as a React component in the MDX file.
172+
173+
<ColorGenerator />
174+
175+
176+
## Importing Components
177+
178+
Just like in regular React, you can import components from other files.
179179

180180
```jsx
181181
import { ColorGenerator } from "/snippets/color-generator.mdx"
182182
```
183183

184-
### Use the component
185-
186-
Add the component to your MDX content wherever needed:
184+
After importing the component, you can use it in your MDX files like this:
187185

188186
```jsx
189187
<ColorGenerator />
190188
```
191189

192-
## Important Considerations
190+
But unlike regular React, you can't import components from every MDX file. Re-usable components can only be referenced from MDX files within the `snippets` folder.
191+
192+
Learn more about this limitation in the [reusable snippets](/reusable-snippets) documentation.
193+
194+
## Considerations
193195

194196
<AccordionGroup>
195197
<Accordion title="Client-Side Rendering Impact">

snippets/color-generator.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ export const ColorGenerator = () => {
2525
}
2626

2727
return (
28-
<div className="p-4 border dark:border-white/20 rounded-xl bg-white dark:bg-white/5 not-prose">
29-
<p className="text-xl mb-4 font-semibold text-zinc-950/80 dark:text-white">HSL Color Generator</p>
30-
28+
<div className="p-4 border dark:border-white/10 rounded-2xl not-prose">
3129
<div className="space-y-4">
3230
<div className="space-y-2">
3331
<label className="block text-sm text-zinc-950/70 dark:text-white/70">

snippets/counter.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ export const Counter = () => {
66

77
return (
88
<div className="flex items-center justify-center">
9-
<div className="flex items-center rounded-lg overflow-hidden border border-zinc-950/20 dark:border-white/20">
9+
<div className="flex items-center rounded-xl overflow-hidden border border-zinc-950/20 dark:border-white/20">
1010
<button
1111
onClick={decrement}
12-
className="flex items-center justify-center h-8 w-8 bg-white hover:bg-zinc-950/10 text-zinc-950/80 dark:bg-zinc-950 dark:hover:bg-white/10 dark:text-white/80 border-r border-zinc-950/20 dark:border-white/20"
12+
className="flex items-center justify-center h-8 w-8 text-zinc-950/80 dark:text-white/80 border-r border-zinc-950/20 dark:border-white/20"
1313
aria-label="Decrease"
1414
>
1515
-
1616
</button>
1717

18-
<div className="flex text-sm items-center justify-center h-8 px-6 bg-white dark:bg-zinc-950/90 text-zinc-950/80 dark:text-white/80 font-medium min-w-[4rem] text-center">
18+
<div className="flex text-sm items-center justify-center h-8 px-6 text-zinc-950/80 dark:text-white/80 font-medium min-w-[4rem] text-center">
1919
{count}
2020
</div>
2121

2222
<button
2323
onClick={increment}
24-
className="flex items-center justify-center h-8 w-8 bg-white hover:bg-zinc-950/10 text-zinc-950/80 dark:bg-zinc-950 dark:hover:bg-white/10 dark:text-white/80 border-l border-zinc-950/20 dark:border-white/20"
24+
className="flex items-center justify-center h-8 w-8 text-zinc-950/80 dark:text-white/80 border-l border-zinc-950/20 dark:border-white/20"
2525
aria-label="Increase"
2626
>
2727
+

0 commit comments

Comments
 (0)