反应道具值定义(具有可见的子道具值),但子道具值未定义

时间:2018-02-14 19:40:12

标签: reactjs undefined render react-props

我可以访问(this.)props.somePropValue并查看其子内容,但在访问(this.)props.somePropValue.subContents时,会返回UNDEFINED

(this.)props.somePropValue = {
    id: 012345,
    subArray: []
}

const SomeComponent = (props) => {

    // somePropValue defined here & subArray IS VISIBLE inside somePropValue
    console.log(props.somePropValue)

    // subArray UNDEFINED here
    console.log(props.somePropValue.subArray)

    return (
        <div />
    )
}

1 个答案:

答案 0 :(得分:0)

解决方案是能够访问JS对象中深层嵌套的值

看起来ramda的功能涵盖R.path()

enter image description here