React child component receiving props as undefined

白昼怎懂夜的黑 提交于 2019-12-12 05:59:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!