无法读取react-redux列表中未定义的属性“ map”

时间:2019-12-05 09:59:45

标签: react-redux

我已经尝试了下面链接中的解决方案,但仍然无法解决。我是React和JS的新手。谁能帮我吗。 @@

precedence

&

这是减速器

const mapStateToProps = state =>{
  return {
    data:{
      names: state.names,
      ages: state.ages,
      genders: state.genders
    },
  };
}; // This  is the copy of array in Redux state, it comes from the reducer.

const ConnectedList = ({data})=>(

  <ul>
    {data.names.map(el => (
      <li key={el.id}>{el.data.names}</li>
    ))}
    {data.ages.map(el => (
      <li key={el.id}>{el.data.ages}</li>
    ))}
    {data.genders.map(el => (
      <li key={el.id}>{el.data.genders}</li>
    ))}
  </ul>
);

const List = connect(mapStateToProps)(ConnectedList);

export default List;

1 个答案:

答案 0 :(得分:0)

好吧,我只需要返回数据,而不需要返回数据内部的var ...

   const mapStateToProps = state =>{
      return {
          data: state.data
      };
    };