[英]Can't fetch item from current slug content- Sanity/Next.js
I'm trying to get the set_name
from the set
schema that is associated to the current slug.我正在尝试从与当前 slug 关联的set
模式中获取set_name
。 *[_type == 'set']{set_name, slug}
is how the schema looks. *[_type == 'set']{set_name, slug}
是模式的外观。 I'm not getting the set_name
when I click on the slug however, and my console isn't showing any errors.但是,当我单击 slug 时,我没有得到set_name
,并且我的控制台没有显示任何错误。
const sets = (setData) => {
return (
<div>
<Header />
<main className="slug-gallery">
<div className='title'>
<h2>{setData.set_name}</h2>
</div>
</main>
</div>
}
export default sets;
export const getServerSideProps = async (pageContext) => {
const setSlug = pageContext.query.slug;
const setQuery = `*[_type == 'set' && slug.current == $setSlug][0]`;
const setData = await client.fetch(setQuery, {setSlug})
return {
props: {setData}
}
}
Nevermind.没关系。 Just needed to do: const sets = ({setData}) => {
只需要做: const sets = ({setData}) => {
Seems like you need to return setData
without braces and props key.似乎您需要返回不带大括号和道具键的setData
。
return setData;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.