-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add useMDXComponents hook * Update snapshot
- Loading branch information
1 parent
1f71e16
commit 07806bb
Showing
5 changed files
with
47 additions
and
42 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
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
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
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
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 |
---|---|---|
@@ -1,39 +1,36 @@ | ||
import React, {Component} from 'react' | ||
import {withMDXComponents} from './mdx-context' | ||
import React from 'react' | ||
import {useMDXComponents} from './mdx-context' | ||
|
||
const defaults = { | ||
inlineCode: 'code', | ||
wrapper: 'div' | ||
} | ||
|
||
class MDXTag extends Component { | ||
render() { | ||
const { | ||
name, | ||
parentName, | ||
props: childProps = {}, | ||
children, | ||
components = {}, | ||
Layout, | ||
layoutProps | ||
} = this.props | ||
const MDXTag = ({ | ||
name, | ||
parentName, | ||
props: childProps = {}, | ||
children, | ||
components: propComponents, | ||
Layout, | ||
layoutProps | ||
}) => { | ||
const components = useMDXComponents(propComponents) | ||
const Component = | ||
components[`${parentName}.${name}`] || | ||
components[name] || | ||
defaults[name] || | ||
name | ||
|
||
const Component = | ||
components[`${parentName}.${name}`] || | ||
components[name] || | ||
defaults[name] || | ||
name | ||
|
||
if (Layout) { | ||
return ( | ||
<Layout components={components} {...layoutProps}> | ||
<Component {...childProps}>{children}</Component> | ||
</Layout> | ||
) | ||
} | ||
|
||
return <Component {...childProps}>{children}</Component> | ||
if (Layout) { | ||
return ( | ||
<Layout components={components} {...layoutProps}> | ||
<Component {...childProps}>{children}</Component> | ||
</Layout> | ||
) | ||
} | ||
|
||
return <Component {...childProps}>{children}</Component> | ||
} | ||
|
||
export default withMDXComponents(MDXTag) | ||
export default MDXTag |