Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 将自定义React组件导入GatsbyJS中的降价_Reactjs_Markdown_Gatsby - Fatal编程技术网

Reactjs 将自定义React组件导入GatsbyJS中的降价

Reactjs 将自定义React组件导入GatsbyJS中的降价,reactjs,markdown,gatsby,Reactjs,Markdown,Gatsby,在GatsbyJS中,在编写标记文件时,如何导入和显示自定义React组件? 我使用的是带有降价支持的官方初学者。它对博客文章非常有用。但是,我现在想在我的标记文件中添加一个自定义的React组件。我需要做什么来实现这一点 这是我的尝试。没有错误,但自定义组件标记不会转换为实际的React组件 post-1\index.md: --- title: My first post date: "2000-01-01" description: Wouldn't it be sweet if ther

在GatsbyJS中,在编写标记文件时,如何导入和显示自定义React组件?

我使用的是带有降价支持的官方初学者。它对博客文章非常有用。但是,我现在想在我的标记文件中添加一个自定义的React组件。我需要做什么来实现这一点

这是我的尝试。没有错误,但自定义组件标记不会转换为实际的React组件

post-1\index.md:

---
title: My first post
date: "2000-01-01"
description: Wouldn't it be sweet if there was a custom React component in here?
---

import CustomComponent from '../../../src/components/CustomComponent.js'

Lorem ipsum dolor.

<CustomComponent title="Test" />

Markdown不支持JSX。您可以使用MDX进行此操作。盖茨比有大量的文档和官方插件来支持该功能。您可以在以下网址阅读更多内容:

MDX将允许您拥有如下所示的MD文件:

import { Chart } from '../components/chart'

The chart is rendered inside our MDX document.

<Chart />
从“../components/Chart”导入{Chart}
该图表在我们的MDX文档中呈现。
你可以在盖茨比应用程序中使用它,如下所示:

从“React”导入React
从“@mdx js/react”导入{MDXProvider}
从“盖茨比插件mdx”导入{MDXRenderer}
从“/your content.mdx”导入mdxContent
导出默认值()=>{
返回(
{mdxContent}
)
}

退房。Markdown不支持JSX。但它如何与官方博客初学者现成的Markdown解析器相结合呢。试试类似或
import { Chart } from '../components/chart'

The chart is rendered inside our MDX document.

<Chart />