Manko
Manko

Reputation: 61

How to use object with variable in react native?

I am new in react native.

My question is pretty simple: I need to change subject of email with a address of consultant. example: Vul uw vraag, naam en adres in{address}

Address is object, so how to make a strings from this : {activeUser.rentalUnit?.address.street} {activeUser.rentalUnit?.address.houseNumber}{activeUser.rentalUnit?.address.postCode} {activeUser.rentalUnit?.address.city} and to make with one variable which I will use in subject and body also. Thank you all :)

    const onSendMail = () => {
    Linking.openURL(
        `mailto:${activeUser.rentalUnit?.complex?.email || '[email protected]'}?subject=${Strings.Board.EmailSubject}&body=${Strings.Board.EmailText} ${
            activeUser.rentalUnit?.address?.street
        }  `,
    );
};

Upvotes: 0

Views: 67

Answers (1)

Michael Bahl
Michael Bahl

Reputation: 3649

Do you mean you wanna concatenation the address string?

const onSendMail = () => {
 const subjectAddress = `${activeUser.rentalUnit?.address.street} ${activeUser.rentalUnit?.address.houseNumber}${activeUser.rentalUnit?.address.postCode} ${activeUser.rentalUnit?.address.city}`
    Linking.openURL(
        `mailto:${activeUser.rentalUnit?.complex?.email || '[email protected]'}?subject=${subjectAddress}&body=${Strings.Board.EmailText} ${
            subjectAddress
        }  `,
    );
};

Upvotes: 1

Related Questions