React ရှိ Array မှ Select အိုင်တမ်များ

ကျွန်ုပ်တို့တွင် dropdown list ၏အကြောင်းအရာများပါသော array တစ်ခုရှိသည်ဆိုပါစို့:

jsxfunction App() {
  const texts = ['text1', 'text2', 'text3', 'text4'];
  const [value, setValue] = useState('');
  
  return <div>
    ...
  </div>;
}

ကွင်းဆက်တစ်ခုအတွင်း ကျွန်ုပ်တို့၏ option tags များကို ဖန်တီးကြပါစို့:

jsxfunction App() {
  const texts = ['text1', 'text2', 'text3', 'text4'];
  const [value, setValue] = useState('');
  
  const options = texts.map((text, index) => {
    return <option key={index}>{text}</option>;
  });
  
  return <div>
    <select value={value} onChange={(event) => setValue(event.target.value)}>
      {options}
    </select>
    <p>
      သင့်ရွေးချယ်မှု: {value}
    </p>
  </div>;
}
Задание 1

Array ထဲတွင် မြို့များစာရင်းကို သိမ်းဆည်းထားသည်ဆိုပါစို့။ ကွင်းဆက်ကို အသုံးပြု၍ ထိုမြို့များ၏ dropdown list ကို ထုတ်ပြပါ။