在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 初學(xué)redux,報錯Cannot read property 'map' of

初學(xué)redux,報錯Cannot read property 'map' of undefined

import React from 'react';
import DifferentLabels from './DifferentLabels'

const DifferentLabelsDiv = ({ todos, toggleTodo }) => (
    <div>
        {todos.map(todo =>
            <DifferentLabels
                key={todo.id}
                {...todo}
            />
        )}
    </div>
)

class DifferentLabelsList extends React.Component {

    render(){
        return (
            <div className={'left_layout'}>
                <div>
                    展示不同標簽
                </div>
                <DifferentLabelsDiv />
            </div>
        )
    }
}

export default DifferentLabelsList;
import React from 'react'
import PropTypes from 'prop-types'

const DifferentLabels = ({ onClick, completed, text }) => (
    <div
    >
        {text}
    </div>
);

export default DifferentLabels

圖片描述

回答
編輯回答
何蘇葉

你的DifferentLabelsDiv 組件有一個todos的屬性,但是你并沒有給這個組件傳遞這個屬性,所以todosundefined,所以你調(diào)用map方法會報錯,
解決方法:

  1. 傳遞todos屬性
  2. DifferentLabelsDiv這個組件一個默認的todos屬性。
2017年4月19日 06:36
編輯回答
舊城人
const DifferentLabelsDiv = ({ todos = [], toggleTodo }) ...

改成這樣

2017年3月12日 23:45