Created
March 28, 2019 13:44
-
-
Save matmalkowski/d9d124ba1951e482f2523c60a4b574a1 to your computer and use it in GitHub Desktop.
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
import * as React from 'react' | |
const useMDXFiles = (rolesMDXs: any) => { | |
const [mods, setMods] = React.useState<any>([]) | |
const importModule = (pathname: string) => rolesMDXs[pathname]() | |
const allPaths = Object.keys(rolesMDXs) | |
const loader = allPaths.map(async (pathname: string) => { | |
const { default: MDXComponent, ...other } = await importModule(pathname) | |
return { MDXComponent, ...other } | |
}) | |
const loadMDXModules = async () => { | |
const modules = await loader | |
Promise.all(modules).then(e => { | |
setMods(e) | |
}) | |
} | |
React.useEffect(() => { | |
loadMDXModules() | |
}, []) | |
return mods | |
} | |
export default useMDXFiles |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment