Reactjs React-如何有条件地显示获取的数据
如果“我的文档”文件夹中没有文档,我想显示“目前没有文档”,但当我这样做时,会收到一条警告信息Reactjs React-如何有条件地显示获取的数据,reactjs,graphql,Reactjs,Graphql,如果“我的文档”文件夹中没有文档,我想显示“目前没有文档”,但当我这样做时,会收到一条警告信息 warn The GraphQL query in the non-page component "/Users/abe/Projects/abechoi/gatsby1.0/abechoi/src/templates/doc-template.js" will not be run. 有没有更好的方法来实现这一点,还是我应该忽略这个警告 export default func
warn The GraphQL query in the non-page component
"/Users/abe/Projects/abechoi/gatsby1.0/abechoi/src/templates/doc-template.js"
will not be run.
有没有更好的方法来实现这一点,还是我应该忽略这个警告
export default function Docs({ data }) {
const docs = data.allMarkdownRemark.nodes
return (
<Layout>
<div className={styles.docsContainer}>
<h2>Docs</h2>
<h3>My Technical Documentations</h3>
{docs.length === 0 ? (
<p>There are no docs at the moment</p>
) : (
<div className={styles.docs}>
{docs.map(doc => (
<Link to={"/docs/" + doc.frontmatter.slug} key={doc.id}>
<div>
<h3>{doc.frontmatter.title}</h3>
</div>
</Link>
))}
</div>
)}
</div>
</Layout>
)
}
export const query = graphql`
query DocsPage {
allMarkdownRemark(
sort: { fields: frontmatter___date, order: DESC }
filter: { frontmatter: { type: { eq: "doc" } } }
) {
nodes {
frontmatter {
title
slug
}
id
}
}
}
`
导出默认函数文档({data}){
const docs=data.allMarkdownRemark.nodes
返回(
文件
我的技术文档
{docs.length==0(
目前没有文档
) : (
{docs.map(doc=>(
{doc.frontmatter.title}
))}
)}
)
}
export const query=graphql`
查询文档{
所有的标记(
排序:{fields:frontmatter\uuuu\u日期,顺序:DESC}
筛选器:{frontmatter:{type:{eq:“doc”}}
) {
节点{
前沿物质{
标题
鼻涕虫
}
身份证件
}
}
}
`
我会使用一个子组件来执行所有检查,然后渲染好的组件
功能完成按钮(){
如果(按钮状态==“暂停”| |按钮状态===“开始”){
返回;
}否则如果(按钮状态==“正在进行”){
返回;
}
返回;
}
这是否回答了您的问题?