I see you already do the string splitting in the file uploader when you create the file image objects. In this case you just need to check the generated productCode of the image object payloads to see if it is already contained in the products array. If it isn't then generate the new "product" state object and add the image to the array, otherwise apply the immutable update pattern to shallow copy state and append the new file object.
Since each product in the action payload could potentially belong to different products you'll need to iterate this array in order to determine where each new product should be merged.
case appConstants.UPLOAD_PRODUCT_SUCCESS:
// (1) iterate the product images array
return action.payload.reduce(
(
state,
{
productCode,
productName,
productCategory,
imageFile,
imageFileName
}
) => {
// (2) Check if the product is already in state
const shouldUpdate = state.products.some(
(product) => product.productCode === productCode
);
// (3a) If we just need to return updated state with added new image
if (shouldUpdate) {
return {
...state,
// (4) shallow copy the products array
products: state.products.map((product) =>
product.productCode === productCode
// (4b) If this is the matching product, shallow copy product
// append a new image file object with new id
? {
...product,
productImages: product.productImages.concat({
id: uuidV4(),
imageFile,
imageFileName
})
}
// (4b) copy forward existing product object
: product
)
};
}
// (3b) Create a new product object and initially populate images array
return {
...state,
products: state.products.concat({
productCode,
productName,
productCategory,
productExisting: true,
productImages: [
{
id: uuidV4(),
imageFile,
imageFileName
}
]
})
};
},
state
);


productImagesarray of a specific product by code? Are you asking how to handle the state update? You seem to be missing an attempt at doing this in your codesandbox._and take the second element from the returned array to match a product code. Once you know which product the image belongs to it's a matter of shallow copying these chunks of state to append the image object into the images array.