问题
I have component Comp1
and it's child Comp2
. The state of markers
is set in the parent component to this object:
var MARKER_ITEMS = {
"item1" : {
"cat" : "wow",
"img" : "slide",
"info" : "bike",
"key" : "1"
},
"item2" : {
"cat" : "omg",
"img" : "slide",
"info" : "4x4",
"key" : "2"
}
};
When I try to generate a Comp2
for each object with loadash _.map
, the props get passed down as undefined.
jsfiddle
回答1:
Your code works but you're using the key
name as a props. key
is a special reserved property name that React uses in order to know which dynamic children a component has.
If you switch from key
to stuff
for example, your code will work.
Read here about it and here
来源:https://stackoverflow.com/questions/28825782/react-child-component-receiving-props-as-undefined