oops, include prebuilder
This commit is contained in:
parent
9e1431d554
commit
6653e6f5b7
2 changed files with 75 additions and 0 deletions
23
sites/shared/hooks/use-dynamic-mdx.mjs
Normal file
23
sites/shared/hooks/use-dynamic-mdx.mjs
Normal file
|
@ -0,0 +1,23 @@
|
|||
import { components } from 'shared/components/mdx/index.mjs'
|
||||
import { Loading } from 'shared/components/spinner.mjs'
|
||||
import { useState, useEffect } from 'react'
|
||||
|
||||
export const useDynamicMdx = (loader, site = 'org') => {
|
||||
// State
|
||||
const [frontmatter, setFrontmatter] = useState({ title: `freeSewing.${site}` })
|
||||
const [MDX, setMDX] = useState(<Loading />)
|
||||
|
||||
/* Load MDX dynamically */
|
||||
useEffect(() => {
|
||||
const loadMDX = async () => {
|
||||
loader().then((mod) => {
|
||||
setFrontmatter(mod.frontmatter)
|
||||
const Component = mod.default
|
||||
setMDX(<Component components={components(site)} />)
|
||||
})
|
||||
}
|
||||
if (loader) loadMDX()
|
||||
}, [loader, site])
|
||||
|
||||
return { MDX, frontmatter }
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue