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

123
Views
how can i use ID instead of index in React

This component will get input from user and then add it into a select option. I used index as a key :

const NewGroup = () => {
    const [group, setGroup] = useState([]);
    const [category, setcategory] = useState("");
    const addToGroup = () => {
      let temp = [...group, category];
      setGroup(temp);
    };
    return (
      <div>
        <input type="text" name="" id="" value={category} onChange={(e) => { setcategory(e.target.value); }} />
        <button onClick={addToGroup}>submit</button>
        <div>
          <select name="" id="">
            {group.map((category, index) => {
              return (
                <option key={index} value="">
                  {category}
                </option>
              );
            })}
          </select>
        </div>
      </div>
    );
  }
  
  export default NewGroup;

But I want to give each new category a unique ID. How can I do that ?

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

0

Generally you should use a unique key not necessarily using id for key; So if your category item has a uniq key you can use it even category name

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!