1
0
Fork 0
freesewing/sites/shared/hooks/use-evaled-mdx.mjs
2023-06-20 19:27:29 +02:00

21 lines
541 B
JavaScript

import { compile, run } from '@mdx-js/mdx'
import * as runtime from 'react/jsx-runtime' // Production.
import { useState, useEffect } from 'react'
export const useEvaledMdx = (mdxStr = '') => {
const [mdxModule, setMdxModule] = useState(false)
useEffect(() => {
;(async () => {
const code = await compile(mdxStr, {
outputFormat: 'function-body',
development: false,
})
const evaled = await run(code, runtime)
setMdxModule(() => evaled.default)
})()
}, [mdxStr])
return mdxModule
}