【发布时间】:2021-09-22 22:42:11
【问题描述】:
您好,我需要有条件地渲染我的导航。我使用 Gatsby 和 GraphQl。我有导航组件,并且取决于我需要渲染不同导航的路线。问题是我无法制作有条件的 useStateStatic 钩子。我在源代码中创建了两个不同的导航,它是 DatoCMS,但我无法查询它。
const Navigation = () => {
const pathName = window.location.pathname;
const data = useStaticQuery(
graphql`
{
datoCmsNavigation(sectionId: { eq: "navigation" }) {
sectionId
logo {
url
alt
}
menuItem {
id
name
href
}
}
}
`
);
const {
datoCmsNavigation: { sectionId, logo, menuItem },
} = data;
return (
<NavBar id={sectionId}>
<NavBarLogoWrapper>
<a href="/">
<img src={logo.url} alt={logo.test} />
</a>
</NavBarLogoWrapper>
<NavBarList>
{menuItem.map((item, index) => (
<NavBarItem key={index}>
<a href={item.href}> {item.name.toLowerCase()}</a>
</NavBarItem>
))}
</NavBarList>
</NavBar>
);
};
这是我的导航组件。有没有人有想法我该如何处理?
【问题讨论】:
标签: reactjs graphql gatsby datocms