简体   繁体   中英

How to dereference values with same name from props

I use to get values from props like this

onSubmit = () => {
    const {
        id,
        client: {
            name,
            surname,
            address
        },
    } = this.props.release

    this.props.onSubmit(id, name, surname, address)
}

now I need to update the onSubmit call passing an additional arg, that in my props object is inside recipient, and the name is address. I can't do this:

const {
    id,
    client: {
        name,
        surname,
        address
    },
    recipient: {
        address
    },
} = this.props.release

this.props.onSubmit(id, name, surname, address, < recipientAddress >)

because this conflicts with address inside client. how can I solve this please?

const {
  id,
  client: {
    name,
    surname,
    address
  },
  recipient: {
    address: recipientAddress
  },
} = this.props.release

this.props.onSubmit(id, name, surname, address, recipientAddress)

And then you can access the address property of recipient object by accessing recipientAddress

You do net need to use destructuring assignment , just use props as is:

onSubmit = () => {
    this.props.onSubmit(
        this.props.release.id,
        this.props.release.client.name, 
        this.props.release.client.surname,
        this.props.release.client.address, 
        this.props.release.recipient.address
    )
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM