我试图仅渲染一个对象属性,但最终会渲染除目标属性之外未定义的所有其他对象。我对Redux,Reducer等还不是很陌生,所以任何帮助都会很棒!
// Letters reducer
export default function() {
return [
{
x: {
start: 10,
finish: 100
}
},
{
y: {
start: 20,
finish: 100
}
},
{
z: {
start: 30,
finish: 100
}
}
];
}
组件
renderList() {
this.props.letters.map(i => {
console.log(i.x.start);
});
}
控制台是
{current: 10, goal: 100}
2 undefined < -- my Y and Z, which idk why it's getting called.
但是如果我尝试这样称呼它,它会起作用
console.log(this.props.letters[0].x.start)
// 10