-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a useComponentDoc hook. Update ReferenceTemplate to use it
- Loading branch information
1 parent
5572f98
commit e3fc863
Showing
2 changed files
with
52 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useMemo } from 'react'; | ||
|
||
const IGNORED_METHODS = [ | ||
'prototype', | ||
'length', | ||
'name', | ||
'propTypes', | ||
'getDerivedStateFromProps', | ||
'defaultProps', | ||
]; | ||
|
||
const useComponentDoc = (componentName) => { | ||
if (typeof window === 'undefined') global.window = {}; | ||
|
||
return useMemo(() => { | ||
const component = window?.__NR1_SDK__?.default?.[componentName]; | ||
|
||
return { | ||
description: component?.__docs__.text, | ||
examples: component?.__docs__.tags.examples ?? [], | ||
methods: Object.getOwnPropertyNames(component).filter( | ||
(member) => | ||
!IGNORED_METHODS.includes(member) && | ||
typeof component[member] === 'function' | ||
), | ||
}; | ||
}, [componentName, window?.__NR1_SDK__]); | ||
}; | ||
|
||
export default useComponentDoc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters