Skip to content

Commit 821de9d

Browse files
dks333ethanpalm
andauthored
feat: support .jsx files (#854)
* support jsx files * add .jsx * Apply suggestions from code review --------- Co-authored-by: Ethan Palm <56270045+ethanpalm@users.noreply.github.com>
1 parent 163ddfa commit 821de9d

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

react-components.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ icon: "react"
55
---
66

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

1010
[React components](https://react.dev) are a powerful way to create interactive and reusable elements in your documentation.
1111

@@ -49,7 +49,7 @@ And the component will be rendered as a React component in the MDX file.
4949
Just like in regular React, you can import components from other files.
5050

5151
```mdx
52-
import { ColorGenerator } from "/snippets/color-generator.mdx"
52+
import { ColorGenerator } from "/snippets/color-generator.jsx"
5353
```
5454

5555
<Warning>
@@ -68,7 +68,7 @@ Learn more about [reusable snippets](/reusable-snippets).
6868

6969
You can also build much more complex components. Here's an example of a color generator component that uses multiple React hooks:
7070

71-
```mdx /snippets/color-generator.mdx [expandable]
71+
```mdx /snippets/color-generator.jsx [expandable]
7272
export const ColorGenerator = () => {
7373
const [hue, setHue] = useState(180)
7474
const [saturation, setSaturation] = useState(50)

reusable-snippets.mdx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,32 @@ import { myName, myObject } from '/snippets/path/to/custom-variables.mdx';
9595

9696
Hello, my name is {myName} and I like {myObject.fruit}.
9797
```
98+
99+
### JSX snippets
100+
101+
1. Export a JSX component from your snippet file. (See [React components](/react-components) for more information):
102+
103+
```js icon=square-js snippets/my-jsx-snippet.jsx
104+
export const MyJSXSnippet = () => {
105+
return (
106+
<div>
107+
<h1>Hello, world!</h1>
108+
</div>
109+
)
110+
}
111+
```
112+
113+
<Note>
114+
Important: When creating JSX snippets, use arrow function syntax (`=>`) rather than function declarations. The `function` keyword is not supported in this context.
115+
</Note>
116+
117+
2. Import the snippet from your destination file and use the component:
118+
119+
```typescript destination-file.mdx
120+
---
121+
title: My title
122+
description: My Description
123+
---
124+
125+
import { MyJSXSnippet } from '/snippets/my-jsx-snippet.jsx';
126+
```
File renamed without changes.

0 commit comments

Comments
 (0)