Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
How to dynamically insert a local variable in to a react JSX map function?

I have this component, that inherits a props with a value of string 'A','B','C' depending on what is getting selected at a parent element the point being is the props.options either 'A' or 'B' or 'C' then I want to leverage this incoming props to be able to select a local option list from options array.. depending on what is being passed down instead of passing the whole options arrays from the parent down to child component... I am trying to use template literals but it's not working any local work around so I could render the options array depending on incoming string props? for this particular case.

// incoming props  string of A or  B or  C depending on what is getting seleted at parent element ! 

function OptionAcordingToProps(props) {
 
 const optionsA = ['x', 'x', 'x'];
 const optionsB = ['y', 'y', 'y'];
 const optionsC = ['z', 'z', 'z'];
 
  return (
    <div>
      <form onSubmit={doSmth}>
        <NativeSelect>
             {`options${props.options}`?.map((option) => (
            <option>{option}</option>
          ))}
        </NativeSelect>
        </form>    
       </div>
  );
}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use an object as a map:

function OptionAcordingToProps(props) {
 
  const options = {
     A: ['x', 'x', 'x'],
     B: ['y', 'y', 'y'],
     C: ['z', 'z', 'z'],
  };
 
  return (
    <div>
      <form onSubmit={doSmth}>
        <NativeSelect>
             {options[props.options]?.map((option) => (
            <option>{option}</option>
          ))}
        </NativeSelect>
        </form>    
       </div>
  );
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!