使用对象destructuring.eslint(prefer-destructuring)

时间:2019-07-15 08:56:13

标签: reactjs react-native

我有以下代码。该代码抱怨Use object destructuring.eslint(prefer-destructuring),如红色标记中的图像所示。我该如何解决这个问题?我在这里看看,但是https://eslint.org/docs/rules/prefer-destructuring不确定我在哪里做错了吗?

GET_GEOCODE_FROM_ZIPCODE(state, action) {
    const { res } = action;
    if (res && res.address && res.zipcode) {
        const zipcode = res.zipcode;
        const address = res.address;
        return {
            ...state,
            geoCode: {...action.res, address},
            zipcode,
            showCallout: true
        }
    } 
    return state
}

enter image description here

2 个答案:

答案 0 :(得分:0)

您必须destructure您的对象:

const { address, zipcode } = res; 

答案 1 :(得分:0)

Eslint希望您使用解构:

const { zipcode, address } = res; 

您可以了解有关对象解构here的更多信息: