javascript - 页面渲染成功后,对象不是有效组件

标签 javascript reactjs react-dom next.js

我正在使用 Next.js 获取页面加载数据。我正在加载一个 markdown 文件并将其解析为一个子组件数组,这些子组件应该使用 Marksy 与 React dom 节点兼容。 。在短时间内,一切似乎都正常工作,通过使用以下粗略结构渲染我的 compiled(markdown).tree ,我在页面上看到了正确的内容:

static async getInitialProps ({query}) {
  const res = await fetch('http://localhost:4000/api/test')
  const json = await res.json()
  return { content: compile(json.data).tree }
}

render () {
  return (
    <div>
      {this.props.content}
    </div>
  )
}

我的数据数组具有以下形状:

[{"type":"h1","key":"0","ref":null,"props":{"children":["Welcome to the Jungle"]},"_owner":null,"_store":{}}]

半秒内,React-Redbox 抛出一个错误,尽管上面写着:

Objects are not valid as a React child (found: object with keys {type, key, ref, props, _owner, _store}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of `_class`.

我正在使用 react 15.4.2

为什么我在成功渲染页面后出现错误?谢谢!

最佳答案

All React elements require an additional $$typeof: Symbol.for('react.element') field declared on the object for security reasons.

添加此属性应该可以解决问题

来源:https://facebook.github.io/react/blog/2015/12/18/react-components-elements-and-instances.html

关于javascript - 页面渲染成功后,对象不是有效组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44118976/

相关文章:

javascript - Heroku 应用程序崩溃

javascript - 从 Firebase OAuth 获取 Twitter 个人资料 url

javascript - 如何在 React Native 应用程序中添加 "Set as Wallpaper"选项

ajax - ajax调用后自动渲染React组件

javascript - 在 observabel 数组中添加的元素不可观察 + ReactJs

javascript - 这些链接不会呈现 ReactJS 的组件。 URL 改变了,但页面没有改变?

c# - 在 gridview asp :hyperlinkfield? 上禁用自动回发

javascript - 我可以通过从 PHP 获取变量来更改 Javascript 中的显示属性吗?

javascript - 使用 React 寻找更好的解决方案来根据窗口大小移动按钮

javascript - Reactjs - 使用 React Hooks 获取 div/图像的高度