小编D.G*_*ves的帖子

TypeError:无法使用ReactJs读取未定义的属性“ map”

我收到“ TypeError:无法读取未定义的属性'map'”。不知道我在哪里出错了。关于React,我还是很新,所以我不知道我是否缺少什么。当我尝试调用this.props.meals.map时,这给了我错误

export class Dashboard extends React.Component {
  componentDidMount() {
    this.props.dispatch(fetchProtectedData());
    this.props.dispatch(retrieveDailyLogs())
    .then(results => {
        return this.props.dispatch(getDailyLogs(results));
    })
}

getId(id) {
   console.log('test');
   this.props.dispatch(removeDay(id))
   this.props.dispatch(retrieveDailyLogs())
  .then(results => {
    return this.props.dispatch(getDailyLogs(results));
});
}


render() {
    const dailyLogs = this.props.meals.map((day, index) => 
    <li className="card" key={index}>
        <Card handleClick={(id) => this.getId(id)} {...day} />
    </li>
    )
    return (
        <section className="dashboard-container">
            <h1>Dashboard</h1>
            <Link className="log-day-btn" to="/dailylogs">Log Meals</Link>
            <ul className="meal-list">
            {dailyLogs}
            </ul>
        </section>
    );
}
}

const mapStateToProps = state => ({
  meals: state.dailyLogsReducer.dailyLogs
});

export default requiresLogin()(connect(mapStateToProps)(Dashboard));
Run Code Online (Sandbox Code Playgroud)

这是我的减速机,以防万一 …

javascript reactjs redux

2
推荐指数
1
解决办法
2684
查看次数

标签 统计

javascript ×1

reactjs ×1

redux ×1