import merge from 'lodash/merge' ; see https param initialValues param values const sanitizeEmptyValues = ( initialValues , values ) => { if ( ! initialValues ) return values ; const initialValuesWithEmptyFields = Object . keys ( initialValues ) . reduce ( ( acc , key ) => { if ( values [ key ] instanceof Date ) { acc [ key ] = values [ key ] ; } else if ( Array . isArray ( values [ key ] ) ) { if ( Array . isArray ( initialValues [ key ] ) ) { acc [ key ] = values [ key ] . map ( ( value , index ) => sanitizeEmptyValues ( initialValues [ key ] [ index ] , value ) ) ; } else { acc [ key ] = values [ key ] ; } } else if ( typeof values [ key ] === 'object' && typeof initialValues [ key ] === 'object' && values [ key ] !== null ) { acc [ key ] = sanitizeEmptyValues ( initialValues [ key ] , values [ key ] ) ; } else { acc [ key ] = typeof values [ key ] === 'undefined' ? null : values [ key ] ; } return acc ; } , { } ) ; return merge ( initialValuesWithEmptyFields , values ) ; } ; export default sanitizeEmptyValues ;