想知道是否ES6的任何部分使这些检查更加简洁:

componentWillReceiveProps(nextProps) {
    if(nextProps && nextProps.filterObj && nextProps.filterObj.area){
        // go ahead
    }
}

最佳答案

不,没有存在运算符已纳入ES6;它是still discussed

当然,您可以使用任何existing methods

if ( ((nextProps||{}).filterObj||{}).area ) {
    // go ahead
}

您也可以尝试解构和默认值:
function componentWillReceiveProps({filterObj: {area} = {}} = {}) {
    if (area) {
        // go ahead
    }
}

09-25 16:34