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

172
Views
How to edit a property of a object on an array?

I have an array in a useState. and I want to edit a property.

const [equipe_montador, setEquipe_Montador] = useState([]);

<Card title="Adicionar Mão de Obra">
        {equipe_montador.map((item, key) =>
            <div key={key}>
                <InputBox type="number" maxLength={6} title={item.nome} value={item.quantidade} onChange={e => setEquipe_Montador([...equipe_montador, { ...item, quantidade: e.target.value }])} />
            </div>
        )}
    </Card>

But, when I edit the value, the item duplicate.

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

0

I've discovered the solution. It's working, but I don't know if is the best approach. I edit the object and create a new list with the edited object.

        <Card title="Adicionar Mão de Obra">
        {equipe_montador.map((item, key) =>
            <div key={key}>
                <InputBox type="number" maxLength={6} title={item.nome} value={item.quantidade} onChange={e => {
                    var new_array = equipe_montador.map((new_obj) => new_obj.id_objeto === item.id_objeto ?
                        {
                            ...new_obj,
                            quantidade: e.target.value
                        } : new_obj);
                    setEquipe_Montador(new_array);
                }
                } />
            </div>
        )}
    </Card>
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!