Skip to content

Instantly share code, notes, and snippets.

@rcdexta
Last active December 31, 2019 06:53
Show Gist options
  • Select an option

  • Save rcdexta/12a0cdcde885330c0d506c5994e06a3f to your computer and use it in GitHub Desktop.

Select an option

Save rcdexta/12a0cdcde885330c0d506c5994e06a3f to your computer and use it in GitHub Desktop.
// Prior to v3.7
if (data && data.customer && data.customer.address) {
const {address} = data.customer
const fullAddress = `${address.street}, ${address.city}, ${address.state }${address.zipcode}`
}
// v3.7 onwards
// data access
const address = data?.customer?.address
const fullAddress = `${address?.street}, ${address?.city}, ${address?.state } ${address?.zipcode}`
// also works with arrays
customers?.[0]?.['address']
// check if method defined and call
customer.approve?.()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment