Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Convert withMDXComponents to use hooks (#417)
- Loading branch information
1 parent
c433fc7
commit 07e3a72
Showing
14 changed files
with
188 additions
and
189 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
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,2 +1,6 @@ | ||
export {default as MDXTag} from './mdx-tag' | ||
export {default as MDXProvider, withMDXComponents} from './mdx-provider' | ||
export { | ||
default as MDXContext, | ||
MDXProvider, | ||
withMDXComponents | ||
} from './mdx-context' |
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,27 @@ | ||
import React from 'react' | ||
|
||
const isFunction = obj => typeof obj === 'function' | ||
|
||
const MDXContext = React.createContext({}) | ||
|
||
export const withMDXComponents = Component => props => { | ||
const contextComponents = React.useContext(MDXContext) | ||
const allComponents = props.components || contextComponents | ||
|
||
return <Component {...props} components={allComponents} /> | ||
} | ||
|
||
export const MDXProvider = props => { | ||
const outerContextComponents = React.useContext(MDXContext) | ||
const allComponents = isFunction(props.components) | ||
? props.components(outerContextComponents) | ||
: props.components | ||
|
||
return ( | ||
<MDXContext.Provider value={allComponents}> | ||
{props.children} | ||
</MDXContext.Provider> | ||
) | ||
} | ||
|
||
export default MDXContext |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.