Skip to content
This repository was archived by the owner on Mar 16, 2026. It is now read-only.

Commit bef0536

Browse files
docs: add useComponentProps doc (#98)
* docs: add useComponentProps doc * docs: update components-api.mdx Co-authored-by: Rakan Nimer <rakannimer@gmail.com>
1 parent b21737b commit bef0536

File tree

1 file changed

+54
-3
lines changed

1 file changed

+54
-3
lines changed

src/docs/documentation/references/components-api.mdx

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ import MyComponent from './MyComponent'
114114

115115
### Descriptions
116116

117-
You can add descriptions for your props by adding a comment on the line above the prop.
117+
You can add descriptions for your props by adding a comment on the line above the prop.
118118

119119
> Note: Description comments must be in the format `/** Description */`.
120120
@@ -290,10 +290,61 @@ export function useConfig(): Config
290290

291291
---
292292

293+
## `useComponentProps`
294+
295+
Available since `v2.3.0`.
296+
297+
Gets you the type definition of a specific component defined by the query.
298+
Can be useful when you need data from type definition found by docgen, one use case would be if you want to filter all components based on a group of type.
299+
300+
```js
301+
import { useComponentProps } from 'docz'
302+
303+
const Props = ({ props, ...others }) => {
304+
const marginProps = useComponentProps({
305+
componentName: 'MarginComponent',
306+
fileName: 'path/to/MarginComponent.js'
307+
})
308+
const filteredProps = filterProps(props, marginProps)
309+
return <DoczProps props={filteredProps} {...others} />
310+
}
311+
```
312+
313+
### Type Definitions
314+
315+
```ts
316+
interface Query {
317+
componentName: string
318+
fileName: string
319+
}
320+
321+
interface PropDefinition {
322+
defaultValue: string
323+
description: string
324+
name: string
325+
parent: string
326+
required: boolean
327+
type: string
328+
}
329+
330+
interface ComponentPropsDefinition {
331+
[propName: string]: PropDefinition
332+
}
333+
334+
useComponentProps(query: Query): ComponentPropsDefinition
335+
```
336+
337+
> **Docgen** can only pickup the type definition of component and function, if you need type definition of a specific interface, you must create a fake component.
338+
339+
```ts
340+
const MarginComponent = (_: MarginProps) => null
341+
```
342+
---
343+
293344
## `theme()`
294345

295-
If you want to create your custom theme you need to use the `theme()` function.
296-
It's a Higher Order Component that receives a `config` property as the first parameter
346+
If you want to create your custom theme you need to use the `theme()` function.
347+
It's a Higher Order Component that receives a `config` property as the first parameter
297348
and returns a function that receives your theme component as a parameter:
298349

299350
```js

0 commit comments

Comments
 (0)