对象作为React子对象(found: object with key {author})无效 &g



这是我的sanity模式,名为blogs还有一个引用字段,名为author

所以我使用博客。作者在我的博客上获取作者姓名出现错误

sanity blog.js中的代码

{
name: 'author',
type: 'object',
fields: [
{
title: 'Author',
name: 'author',
type: 'reference',
to: [{type: 'author'}]
}
]
}

nextjs slug.js页面中的代码

{blog.author}

得到误差

Error: Objects are not valid as a React child (found: object with keys {author}). If you meant to render a collection of children, use an array instead.

如Jacob所说,blog.author是一个对象。您可能想要输出类似blog.author.name的内容(但是如果没有看到author模式就很难知道)。您还需要确保在查询中解引用(即遵循对author的引用)。