React + Redux,render()没有返回任何内容

时间:2018-07-17 17:44:48

标签: javascript reactjs redux jsx

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>;
 }
}

1 个答案:

答案 0 :(得分: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>;
    }
}