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

88
Views
React Hooks Modificar matriz en la tabla

Tengo problemas para modificar los valores de React de una matriz con useState después de representarlos en una tabla. Aquí hay un ejemplo simple:

 //The hook const [awayAbilityAdjust, setAwayAbilityAdjust] = useState([1, 1, 1, 1, 1]);

Ahora, lo renderizo en una tabla en Bootstrap con un Form :

 <tr> <td>Ability Adjust</td> {awayAbilityAdjust.map((ability, index) => ( <td key={index}> <Form.Control size="sm" type="number" name="ability-input" step="0.1" value={ability} style={{ width: "50px", backgroundColor: "#6d784b", color: "#ffff", }} min="0" max="10" onChange={updateHomeAbility(index) } /> </td> ))} </tr>

Aquí está updateHomeAbility :

 const updateHomeAbility = (index) => (e) => { const updatedArray = [...homeAbilityAdjust]; homeAbilityAdjust[index] = e.target.value; setHomeAbilityAdjust(updatedArray); };

Sin embargo, esto no cambia ninguno de los valores cuando selecciono los botones arriba y abajo en el Form . ¿Cómo puedo modificar estos valores usando useState ?

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

0

Está actualizando homeAbilityAdjust después de copiarlo en updatedArray . Simplemente necesita actualizar updatedArray en su lugar.

 const updateHomeAbility = (index) => (e) => { const updatedArray = [...homeAbilityAdjust]; updatedArray[index] = e.target.value; setHomeAbilityAdjust(updatedArray); };
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!