2

mdxjs.com 的入门文档中,我们看到以下文档:

Defining variables with exports
If you need to define a variable in your MDX document, you can use an export to do so. Not only do exports emit data, they instantiate data you can reference in JSX blocks:

export const myVariable = 'Yay!'

# Hello, world!

<div>{myVariable}</div>

但是,如果我们复制该代码并将其粘贴到操场上:https ://mdxjs.com/playground ,它会失败并显示ReferenceError: myVariable is not defined.

当我尝试将 MDX 文档导入我的 nextjs 应用程序时,我遇到了同样的问题。

这有效:

Sentence with details about <Text product={product}/>

Where<Text/>只是一个虚拟组件:

const Text = ({ product }) => {
    return (
        <>{product}</>
    )
}

但我不应该这样做。我只是希望我的 MDX 看起来像这样:

Sentence with details about {product}

我在这里错过了什么吗?

感谢你的帮助!

4

0 回答 0