<small id='pZuxi'></small><noframes id='pZuxi'>

  • <legend id='pZuxi'><style id='pZuxi'><dir id='pZuxi'><q id='pZuxi'></q></dir></style></legend>

      <i id='pZuxi'><tr id='pZuxi'><dt id='pZuxi'><q id='pZuxi'><span id='pZuxi'><b id='pZuxi'><form id='pZuxi'><ins id='pZuxi'></ins><ul id='pZuxi'></ul><sub id='pZuxi'></sub></form><legend id='pZuxi'></legend><bdo id='pZuxi'><pre id='pZuxi'><center id='pZuxi'></center></pre></bdo></b><th id='pZuxi'></th></span></q></dt></tr></i><div id='pZuxi'><tfoot id='pZuxi'></tfoot><dl id='pZuxi'><fieldset id='pZuxi'></fieldset></dl></div>
    1. <tfoot id='pZuxi'></tfoot>

          <bdo id='pZuxi'></bdo><ul id='pZuxi'></ul>
      1. 您可能返回了未定义、数组或其他一些无效的对象渲染状态数据

        You may have returned undefined, an array or some other invalid object rendering state data(您可能返回了未定义、数组或其他一些无效的对象渲染状态数据)

        <i id='vcNe9'><tr id='vcNe9'><dt id='vcNe9'><q id='vcNe9'><span id='vcNe9'><b id='vcNe9'><form id='vcNe9'><ins id='vcNe9'></ins><ul id='vcNe9'></ul><sub id='vcNe9'></sub></form><legend id='vcNe9'></legend><bdo id='vcNe9'><pre id='vcNe9'><center id='vcNe9'></center></pre></bdo></b><th id='vcNe9'></th></span></q></dt></tr></i><div id='vcNe9'><tfoot id='vcNe9'></tfoot><dl id='vcNe9'><fieldset id='vcNe9'></fieldset></dl></div>

          <bdo id='vcNe9'></bdo><ul id='vcNe9'></ul>
          • <legend id='vcNe9'><style id='vcNe9'><dir id='vcNe9'><q id='vcNe9'></q></dir></style></legend>

                <tbody id='vcNe9'></tbody>
              <tfoot id='vcNe9'></tfoot>

              <small id='vcNe9'></small><noframes id='vcNe9'>

                  本文介绍了您可能返回了未定义、数组或其他一些无效的对象渲染状态数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 React 中迭代列表和打印元素时遇到问题.

                  反应代码是:

                  从'react'导入反应;从 'react-dom' 导入 ReactDOM;类 NewComponent 扩展 React.Component {构造函数(道具){超级(道具);this.state = {myData: []}}组件WillMount(){让数据 = document.getElementById('demo').innerHTML;数据 = JSON.parse(数据);this.setState({myData: 数据});}使成为() {返回 this.state.myData.map((item) => {返回 (

                  <h3>{item.title}</h3><p>{item.description}</p></div>);});}}ReactDOM.render(<新组件/>,document.getElementById('demo'))

                  我收到以下错误:

                  bundle.js:830 Uncaught Error: NewComponent.render(): A valid React element(或 null)必须返回.您可能返回了未定义的数组或其他一些无效的对象.

                  我很确定在渲染函数中的返回有一些问题不过不确定是什么问题.

                  编辑

                  我进行了以下编辑,错误不再存在,但没有呈现任何内容.

                  renderList() {console.log("正在运行");返回 this.state.myData.map((item) => {

                  <h3>{item.title}</h3><p>{item.description}</p></div>});}使成为() {控制台.log(this.state.myData);如果(this.state.myData.length)return <div>{this.renderList()}</div>别的返回 <div>加载中...</div>}

                  在 Chrome 控制台中我得到:

                  (2) [{…}, {…}]0:{_id: {…},描述:你好",标题:sankit"}1:{_id:{…},描述:让我们添加一些新东西",标题:嗨"}长度:2_proto_:数组(0)跑步

                  解决方案

                  你可以做的是从 render 方法中提取你的 js 代码到一个单独的方法中,像这样:

                  renderList() {返回 this.state.myData.map((item) => {

                  <h3>{item.title}</h3><p>{item.description}</p></div>})}

                  然后在你的渲染方法中:

                  render() {如果(this.state.myData.length){返回 (<div>{this.renderList()}</div>);}别的{返回 (<div>加载中...</div>);}}

                  Have been facing issue while iterating through a list and printing elements in React.

                  The React Code is:

                  import React from 'react';
                  import ReactDOM from 'react-dom';
                  
                  class NewComponent extends React.Component {
                      constructor(props){
                          super(props);
                          this.state = {myData: []}
                      }
                  
                      componentWillMount(){
                          let data = document.getElementById('demo').innerHTML;
                          data = JSON.parse(data);
                          this.setState({myData: data});
                      }
                  
                      render() {
                          return this.state.myData.map((item) => {
                          return (
                              <div>
                                  <h3>{item.title}</h3>
                                  <p>{item.description}</p>
                              </div>
                              );
                           });
                         }
                       }
                  
                  
                  ReactDOM.render(
                      <NewComponent />,
                      document.getElementById('demo')
                   )
                  

                  And I'm getting an error of:

                  bundle.js:830 Uncaught Error: NewComponent.render(): A valid React element 
                  (or null) must be returned. You may have returned undefined, an array or 
                  some other invalid object.
                  

                  I'm pretty sure there is some issue with returns in the render function of the Not sure what is the issue though.

                  EDITS

                  I have made the following edits, the error is not there anymore but nothing is rendering.

                  renderList() {
                  console.log("Running");
                  return  this.state.myData.map((item) => {
                      <div>
                        <h3>{item.title}</h3>
                        <p>{item.description}</p>
                      </div>
                    });
                  }
                  
                  render() {
                      console.log(this.state.myData);
                      if(this.state.myData.length)
                          return <div>{this.renderList()}</div>
                      else
                          return <div>Loading...</div>
                   }
                  

                  In Chrome console I'm getting:

                  (2) [{…}, {…}]
                   0:{_id: {…}, description: "hello", title: "sankit"}
                   1:{_id: {…}, description: "lets add some thing new", title: "hi"}
                   length:2
                   _proto_:Array(0)
                  
                   Running
                  

                  解决方案

                  what you can do is extract your js code from the render method in a separate method like so:

                  renderList() {
                     return this.state.myData.map((item) => {
                        <div>
                         <h3>{item.title}</h3>
                         <p>{item.description}</p>
                        </div>
                     })
                  }
                  

                  then in your render method:

                  render() {
                    if(this.state.myData.length){
                      return (
                         <div>{this.renderList()}</div>
                      );
                    }
                    else
                    {
                      return (
                        <div>Loading...</div>
                      );
                    }
                  }
                  

                  这篇关于您可能返回了未定义、数组或其他一些无效的对象渲染状态数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                  getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)
                  How do I make a TextGeometry multiline? How do I put it inside a square so it wraps like html text does inside a div?(如何制作 TextGeometry 多线?如何将它放在一个正方形内,以便它像 html 文本一样包裹在 div 内?) - IT屋-程序员软件开发技术分享社

                  <small id='DPNWL'></small><noframes id='DPNWL'>

                    • <i id='DPNWL'><tr id='DPNWL'><dt id='DPNWL'><q id='DPNWL'><span id='DPNWL'><b id='DPNWL'><form id='DPNWL'><ins id='DPNWL'></ins><ul id='DPNWL'></ul><sub id='DPNWL'></sub></form><legend id='DPNWL'></legend><bdo id='DPNWL'><pre id='DPNWL'><center id='DPNWL'></center></pre></bdo></b><th id='DPNWL'></th></span></q></dt></tr></i><div id='DPNWL'><tfoot id='DPNWL'></tfoot><dl id='DPNWL'><fieldset id='DPNWL'></fieldset></dl></div>
                    • <legend id='DPNWL'><style id='DPNWL'><dir id='DPNWL'><q id='DPNWL'></q></dir></style></legend>

                        <bdo id='DPNWL'></bdo><ul id='DPNWL'></ul>
                      • <tfoot id='DPNWL'></tfoot>
                          <tbody id='DPNWL'></tbody>