【发布时间】:2019-07-23 09:52:29
【问题描述】:
我正在使用 Gatsby(React 和 Graphql)编写一个小型博客应用程序。有个小东西我不太明白。这是我的博客页面代码:
const Blog = ({ data }) => {
console.log(data)
return (
<Layout>
<h1>Blog</h1>
{data.allMarkdownRemark.edges.map(({ node }) => (
<div key={node.id}>
<h3>{node.frontmatter.title}</h3>
</div>
))}
</Layout>)
}
export default props => (
<StaticQuery
query={graphql`
query {
allMarkdownRemark {
totalCount
edges {
node {
id
frontmatter {
title
path
date
tags
}
}
}
}
}
`}
render={ data => <Blog data={data} {...props} />}
/>
)
让我感到困惑的是这一行:
{data.allMarkdownRemark.edges.map(({ node }) => (
我的问题是,为什么这会返回错误:
{data.allMarkdownRemark.edges.map( node => (
为什么需要大括号?混淆来自于我们已经从 markdownremark.edges 接收列表的事实,那么为什么我们必须再次指定它是动态生成的内容呢?这是一个graphql的东西吗?
很高兴知道答案,在此先感谢。
【问题讨论】: