Skip to content

Commit 02f5075

Browse files
committed
add response fields and move reusable snippets components to components section
1 parent 92bdbc1 commit 02f5075

File tree

5 files changed

+80
-73
lines changed

5 files changed

+80
-73
lines changed

content/components/custom-components.mdx

Lines changed: 0 additions & 7 deletions
This file was deleted.

content/components/responses.mdx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,20 @@ The `<ResponseField>` component is designed to define the return values of an AP
1010
A response field example
1111
</ResponseField>
1212

13-
<RequestExample>
14-
15-
```jsx ResponseField Example
13+
```jsx
1614
<ResponseField name="response" type="string" required>
1715
A response field example
1816
</ResponseField>
1917
```
2018

21-
</RequestExample>
22-
2319
## Props
2420

2521
<ResponseField name="name" type="string" required>
2622
The name of the response value.
2723
</ResponseField>
2824

2925
<ResponseField name="type" type="string" required>
30-
Expected type of the response value
26+
Expected type of the response value, you can also pass a custom type string
3127
</ResponseField>
3228

3329
<ResponseField name="default" type="string">
@@ -37,3 +33,15 @@ The `<ResponseField>` component is designed to define the return values of an AP
3733
<ResponseField name="required" type="boolean">
3834
Show "required" beside the field name.
3935
</ResponseField>
36+
37+
<ResponseField name="deprecated" type="boolean">
38+
Show "deprecated" beside the field name.
39+
</ResponseField>
40+
41+
<ResponseField name="pre" type="string[]">
42+
Labels that are shown before the name of the field
43+
</ResponseField>
44+
45+
<ResponseField name="post" type="string[]">
46+
Labels that are shown after the name of the field
47+
</ResponseField>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: "Reusable Components"
3+
description: "Reusable, custom component snippets"
4+
icon: "recycle"
5+
---
6+
7+
Much like custom content [snippets](/reusable-snippets) that can be added in MDX files, you can add reusable components as snippets.
8+
9+
## Creating a reusable React component
10+
11+
1. Inside your snippet file, create a component that takes in props by exporting your component in the form of an arrow function.
12+
13+
```typescript snippets/custom-component.mdx
14+
export const MyComponent = ({ title }) => (
15+
<div>
16+
<h1>{title}</h1>
17+
<p>... snippet content ...</p>
18+
</div>
19+
);
20+
```
21+
22+
<Warning>
23+
MDX does not compile inside the body of an arrow function. Stick to HTML
24+
syntax when you can or use a default export if you need to use MDX inside of your component.
25+
</Warning>
26+
27+
2. Import the snippet into your destination file and pass in the props
28+
29+
```typescript destination-file.mdx
30+
---
31+
title: My title
32+
description: My Description
33+
---
34+
35+
import { MyComponent } from '/snippets/custom-component.mdx';
36+
37+
Lorem ipsum dolor sit amet.
38+
39+
<MyComponent title={'Custom title'} />
40+
```
41+
42+
43+
## Client-Side Content
44+
45+
By default, Mintlify employs server-side rendering, generating content
46+
at build time. For client-side content loading, ensure to verify the
47+
`document` object's availability before initiating the rendering process.
48+
49+
```typescript snippets/client-component.mdx
50+
{/* `setTimeout` simulates a React.useEffect, which is called after the component is mounted. */}
51+
export const ClientComponent = () => {
52+
if (typeof document === "undefined") {
53+
return null;
54+
} else {
55+
setTimeout(() => {
56+
const clientComponent = document.getElementById("client-component");
57+
if (clientComponent) {
58+
clientComponent.innerHTML = "Hello, client-side component!";
59+
}
60+
}, 1);
61+
62+
return <div id="client-component"></div>
63+
}
64+
}
65+
```

docs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@
205205
{
206206
"group": "Custom Components",
207207
"pages": [
208-
"content/components/custom-components"
208+
"content/components/reusable-components"
209209
]
210210
},
211211
{

reusable-snippets.mdx

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ should create a custom snippet to keep your content in sync.
2828
Hello world! This is my content I want to reuse across pages.
2929
```
3030

31-
3231
2. Import the snippet into your destination file.
3332

3433
```typescript destination-file.mdx
@@ -96,61 +95,3 @@ import { myName, myObject } from '/snippets/path/to/custom-variables.mdx';
9695

9796
Hello, my name is {myName} and I like {myObject.fruit}.
9897
```
99-
100-
### Reusable components
101-
102-
1. Inside your snippet file, create a component that takes in props by exporting
103-
your component in the form of an arrow function.
104-
105-
```typescript snippets/custom-component.mdx
106-
export const MyComponent = ({ title }) => (
107-
<div>
108-
<h1>{title}</h1>
109-
<p>... snippet content ...</p>
110-
</div>
111-
);
112-
```
113-
114-
<Warning>
115-
MDX does not compile inside the body of an arrow function. Stick to HTML
116-
syntax when you can or use a default export if you need to use MDX.
117-
</Warning>
118-
119-
2. Import the snippet into your destination file and pass in the props
120-
121-
```typescript destination-file.mdx
122-
---
123-
title: My title
124-
description: My Description
125-
---
126-
127-
import { MyComponent } from '/snippets/custom-component.mdx';
128-
129-
Lorem ipsum dolor sit amet.
130-
131-
<MyComponent title={'Custom title'} />
132-
```
133-
134-
### Client-Side Content
135-
136-
By default, Mintlify employs server-side rendering, generating content
137-
at build time. For client-side content loading, ensure to verify the
138-
`document` object's availability before initiating the rendering process.
139-
140-
```typescript snippets/client-component.mdx
141-
{/* `setTimeout` simulates a React.useEffect, which is called after the component is mounted. */}
142-
export const ClientComponent = () => {
143-
if (typeof document === "undefined") {
144-
return null;
145-
} else {
146-
setTimeout(() => {
147-
const clientComponent = document.getElementById("client-component");
148-
if (clientComponent) {
149-
clientComponent.innerHTML = "Hello, client-side component!";
150-
}
151-
}, 1);
152-
153-
return <div id="client-component"></div>
154-
}
155-
}
156-
```

0 commit comments

Comments
 (0)