【问题标题】:React + Redux, nothing returned from render()React + Redux,render() 没有返回任何内容
【发布时间】:2018-12-25 12:19:32
【问题描述】:

render()data 返回的不是array,也不是undefinednull(检查debugger)。它迭代了所有需要的数据,但没有返回任何数据。

如果需要,您可以在这里找到完整代码:https://github.com/BakuganXD/taskManager/tree/boardUpdate

Component.js:

class ProfilePage extends React.Component {

//several functions

render() {
const { loading, error, data, isEditing, editToogle } = this.props;
if (!loading && !error) {
  {data.map( (value, index) => {
    if (!isEditing[value.id]) {
      return (
        //a lot of JSX code, value is not undefined
    } else {
      return (
        //another big JSX part
          );
        }
      }
  ) }
  } else return <p>Loading</p>;
 }
}

【问题讨论】:

  • 您介意更好地格式化您的代码吗?您在此处的内容在语法上无效。
  • 应该是return data.map... 而不是data.map...。你不会从render 返回任何东西,你的return 语句在map 本身中。

标签: javascript reactjs redux jsx


【解决方案1】:

您需要返回data.map 结果。另外,删除{} 周围的data.map

class ProfilePage extends React.Component {

    //several functions

    render() {
        const { loading, error, data, isEditing, editToogle } = this.props;
        if (!loading && !error) {
            return data.map( (value, index) => {
                if (!isEditing[value.id]) {
                  return (
                    //a lot of JSX code, value is not undefined
                  )
                } else {
                return (
                  //another big JSX part
              );
            }
          })
        } else return <p>Loading</p>;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-09
    • 1970-01-01
    • 2021-07-25
    • 2020-09-02
    • 2021-08-19
    • 2020-07-24
    • 2020-09-14
    • 2018-07-30
    相关资源
    最近更新 更多