Dynamically Change part of variable name?interface states and props in typescript reactHow get value datapicker in react toobox custom?Dynamically create components in ReactInitialize state with dynamic key based on props in reactJSmust be wrapped in an enclosing tagHow to send value to state using react bootstrap FormControl dropdown?Redux Form Wizard, button to send json field data?ModalFilterPicker load more on scrollHow to refactor React code to include less of 'this.state'What does React.component in React apart from creating instance of our component and setting props object on it?
Which meaning of "must" does the Slow spell use?
Is a Centaur PC considered an animal when calculating carrying capacity for vehicles?
Can a DM change an item given by another DM?
Find most "academic" implementation of doubly linked list
Will removing shelving screws from studs damage the studs?
Find feasible point in polynomial time in linear programming
How do I insert two edge loops equally spaced from the edges?
Why is there not a willingness from the world to step in between Pakistan and India?
Was a star-crossed lover
Drawing probabilities on a simplex in TikZ
Units in general relativity
Why did James Cameron decide to give Alita big eyes?
How to say "I only speak one which is English." in French?
Using a JoeBlow Sport pump on a presta valve
Dotted background on a flowchart
Federal Pacific 200a main panel problem with oversized 100a 2pole breaker
Why does Windows store Wi-Fi passwords in a reversible format?
How to pass 2>/dev/null as a variable?
Why did the population of Bhutan drop by 70% between 2007 and 2008?
Why was this commercial plane highly delayed mid-flight?
Biological refrigeration?
How could a self contained organic body propel itself in space
Shift lens vs move body?
To what extent should we fear giving offense?
Dynamically Change part of variable name?
interface states and props in typescript reactHow get value datapicker in react toobox custom?Dynamically create components in ReactInitialize state with dynamic key based on props in reactJSmust be wrapped in an enclosing tagHow to send value to state using react bootstrap FormControl dropdown?Redux Form Wizard, button to send json field data?ModalFilterPicker load more on scrollHow to refactor React code to include less of 'this.state'What does React.component in React apart from creating instance of our component and setting props object on it?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
In React, is it possible to dynamically change part of a variable name based on state?
For example, I'm feeding several components information from a JSON file. Depending on the chosen gender (male or female), I want to send the 'atlas' from either the "male_clothes.js" or the "female_clothes.js".
JSX Code:
class App extends Component {
constructor(props) {
super(props)
this.state =
current_gender: "male",
current_pants: 0,
<LimbSegment atlas=male_clothes[this.state.current_pants]['atlas']/>
reactjs
add a comment |
In React, is it possible to dynamically change part of a variable name based on state?
For example, I'm feeding several components information from a JSON file. Depending on the chosen gender (male or female), I want to send the 'atlas' from either the "male_clothes.js" or the "female_clothes.js".
JSX Code:
class App extends Component {
constructor(props) {
super(props)
this.state =
current_gender: "male",
current_pants: 0,
<LimbSegment atlas=male_clothes[this.state.current_pants]['atlas']/>
reactjs
so you want to changemale_clothes
? depending on what state?
– Alexandr Zavalii
Mar 27 at 19:48
add a comment |
In React, is it possible to dynamically change part of a variable name based on state?
For example, I'm feeding several components information from a JSON file. Depending on the chosen gender (male or female), I want to send the 'atlas' from either the "male_clothes.js" or the "female_clothes.js".
JSX Code:
class App extends Component {
constructor(props) {
super(props)
this.state =
current_gender: "male",
current_pants: 0,
<LimbSegment atlas=male_clothes[this.state.current_pants]['atlas']/>
reactjs
In React, is it possible to dynamically change part of a variable name based on state?
For example, I'm feeding several components information from a JSON file. Depending on the chosen gender (male or female), I want to send the 'atlas' from either the "male_clothes.js" or the "female_clothes.js".
JSX Code:
class App extends Component {
constructor(props) {
super(props)
this.state =
current_gender: "male",
current_pants: 0,
<LimbSegment atlas=male_clothes[this.state.current_pants]['atlas']/>
reactjs
reactjs
edited Mar 27 at 20:21
Adam Weiler
asked Mar 27 at 19:45
Adam WeilerAdam Weiler
961 silver badge9 bronze badges
961 silver badge9 bronze badges
so you want to changemale_clothes
? depending on what state?
– Alexandr Zavalii
Mar 27 at 19:48
add a comment |
so you want to changemale_clothes
? depending on what state?
– Alexandr Zavalii
Mar 27 at 19:48
so you want to change
male_clothes
? depending on what state?– Alexandr Zavalii
Mar 27 at 19:48
so you want to change
male_clothes
? depending on what state?– Alexandr Zavalii
Mar 27 at 19:48
add a comment |
3 Answers
3
active
oldest
votes
const current_pants, gender = this.state // I assume gender is comming from the state
const clothes = gender === 'male' ? male_clothes : female_clothes
const atlas = clothes[current_pants].atlas
// Then:
<LimbSegment atlas=atlas/>
add a comment |
not sure if I understood you correctly.
So if the state.gender
is male
it will use male_clothes
otherwise female_clothes
<LimbSegment atlas=this.state.gender === 'male' ?
male_clothes[this.state.current_pants]['atlas'] :
female_clothes[this.state.current_pants]['atlas']/>
add a comment |
Short one:
<LimbSegment atlas=(this.state.someFlag ? male_clothes : female_clothes)[this.state.current_pants]['atlas']/>
But it is better to use more verbose approach:
const clothes = this.state.someFlag ? male_clothes : female_clothes;
...
<LimbSegment atlas=clothes[this.state.current_pants]['atlas']/>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55385348%2fdynamically-change-part-of-variable-name%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
const current_pants, gender = this.state // I assume gender is comming from the state
const clothes = gender === 'male' ? male_clothes : female_clothes
const atlas = clothes[current_pants].atlas
// Then:
<LimbSegment atlas=atlas/>
add a comment |
const current_pants, gender = this.state // I assume gender is comming from the state
const clothes = gender === 'male' ? male_clothes : female_clothes
const atlas = clothes[current_pants].atlas
// Then:
<LimbSegment atlas=atlas/>
add a comment |
const current_pants, gender = this.state // I assume gender is comming from the state
const clothes = gender === 'male' ? male_clothes : female_clothes
const atlas = clothes[current_pants].atlas
// Then:
<LimbSegment atlas=atlas/>
const current_pants, gender = this.state // I assume gender is comming from the state
const clothes = gender === 'male' ? male_clothes : female_clothes
const atlas = clothes[current_pants].atlas
// Then:
<LimbSegment atlas=atlas/>
answered Mar 27 at 19:51
nico.amabilenico.amabile
1721 silver badge10 bronze badges
1721 silver badge10 bronze badges
add a comment |
add a comment |
not sure if I understood you correctly.
So if the state.gender
is male
it will use male_clothes
otherwise female_clothes
<LimbSegment atlas=this.state.gender === 'male' ?
male_clothes[this.state.current_pants]['atlas'] :
female_clothes[this.state.current_pants]['atlas']/>
add a comment |
not sure if I understood you correctly.
So if the state.gender
is male
it will use male_clothes
otherwise female_clothes
<LimbSegment atlas=this.state.gender === 'male' ?
male_clothes[this.state.current_pants]['atlas'] :
female_clothes[this.state.current_pants]['atlas']/>
add a comment |
not sure if I understood you correctly.
So if the state.gender
is male
it will use male_clothes
otherwise female_clothes
<LimbSegment atlas=this.state.gender === 'male' ?
male_clothes[this.state.current_pants]['atlas'] :
female_clothes[this.state.current_pants]['atlas']/>
not sure if I understood you correctly.
So if the state.gender
is male
it will use male_clothes
otherwise female_clothes
<LimbSegment atlas=this.state.gender === 'male' ?
male_clothes[this.state.current_pants]['atlas'] :
female_clothes[this.state.current_pants]['atlas']/>
answered Mar 27 at 19:49
Alexandr ZavaliiAlexandr Zavalii
1,0701 gold badge9 silver badges26 bronze badges
1,0701 gold badge9 silver badges26 bronze badges
add a comment |
add a comment |
Short one:
<LimbSegment atlas=(this.state.someFlag ? male_clothes : female_clothes)[this.state.current_pants]['atlas']/>
But it is better to use more verbose approach:
const clothes = this.state.someFlag ? male_clothes : female_clothes;
...
<LimbSegment atlas=clothes[this.state.current_pants]['atlas']/>
add a comment |
Short one:
<LimbSegment atlas=(this.state.someFlag ? male_clothes : female_clothes)[this.state.current_pants]['atlas']/>
But it is better to use more verbose approach:
const clothes = this.state.someFlag ? male_clothes : female_clothes;
...
<LimbSegment atlas=clothes[this.state.current_pants]['atlas']/>
add a comment |
Short one:
<LimbSegment atlas=(this.state.someFlag ? male_clothes : female_clothes)[this.state.current_pants]['atlas']/>
But it is better to use more verbose approach:
const clothes = this.state.someFlag ? male_clothes : female_clothes;
...
<LimbSegment atlas=clothes[this.state.current_pants]['atlas']/>
Short one:
<LimbSegment atlas=(this.state.someFlag ? male_clothes : female_clothes)[this.state.current_pants]['atlas']/>
But it is better to use more verbose approach:
const clothes = this.state.someFlag ? male_clothes : female_clothes;
...
<LimbSegment atlas=clothes[this.state.current_pants]['atlas']/>
answered Mar 27 at 19:51
UjinT34UjinT34
2,5001 gold badge3 silver badges16 bronze badges
2,5001 gold badge3 silver badges16 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55385348%2fdynamically-change-part-of-variable-name%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
so you want to change
male_clothes
? depending on what state?– Alexandr Zavalii
Mar 27 at 19:48