Search code examples
reactjsreact-props

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?


Solution

  • 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