I suspect the answer is "you can't" but there are a lot of people here who are brighter than I.
In reviewing (and re-writing) code I wrote a year-ish ago (before I learned redux), I have a react component that contains the following destructing of a user profile passed to as a prop as user
:
const {user} = props;
const {
email, username, salutation, firstName, middleName, lastName, suffix, company, title,
securityQuestionNo1, securityAnswerNo1, securityQuestionNo2, securityAnswerNo2,
securityQuestionNo3, securityAnswerNo3, email1, email2, telNo, altTelNo, shippingAddress1,
shippingAddress2, shippingAddress3, shippingCity, shippingState, shippingPostalCode,
shippingNation, billingAddress1, billingAddress2, billingAddress3, billingCity,
billingState, billingPostalCode, billingNation, planChoice, cardName, cardType, cardNumber,
expiryMM, expiryYYYY, cvv,
} = user;
Is there a less ghastly way to declare all these variables inside my component? Is there anyway to move this eyesore above into a separate file and import the variables? Something that's better than changing all subsequent appearances of these variables user.email
, user.username
, etc. (I thought of using var
and moving the declaration to the bottom of the file, but these are not things that should be global variables.)
To the person who suggested that string editing was the way to go, the answer is NO, because (a) it's slow because converting between JSON.stringify objects and back to objects is slow, (b) it's also insecure (someone can inject a string into you code easily enough, since this code will be running on the front end), and (c) it's terrible form, for which Uncle Bob, should he do JS, would scold you extensively.