Redux动作属性默认为' undefined'而不是一个空数组

时间:2017-12-03 00:30:04

标签: arrays redux

我注意到在redux中设置和初始状态操作对象时,空数组返回undefined,这使我无法访问.push().length等数组方法。

有没有办法阻止值从简化到未定义?

export const startAddCustomer = (customerData = {}) => {
    return (dispatch) => {
        const {
            name = '',
            age = 0,
            address = {
                address: '',
                city: '',
                state: ''
            },
            coats = [],
            shoes = [],
            phoneNumber = '',
            dependants = [],
            visits = [],
        } = customerData;
        const customer = {
            name,
            age,
            address,
            coats,
            shoes,
            phoneNumber,
            dependants,
            visits
        };

        database.ref('customers').push(customer).then((ref) => {
            dispatch(addCustomer({
                id: ref.key,
                ...customer
            }))
        })

    }
}; 

0 个答案:

没有答案