I have the following destructuring:
const {
user: {
username,
image,
uid
} = {},
gallery: {
image: picture,
} = {},
} = data
The problem is gallery is sometimes null (not the picture within gallery), even though what I need is the picture within gallery when it exists. In other words, gallery: null, not gallery.image: null.
Therefore, I get:
null is not an object
error message for gallery.image.
How do I conditionally destructure so that gallery.image is used when it exists, but gallery isn't destructured when null?