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

206
Views
la matriz inversa no tiene efecto

Intento ordenar mi matriz en reversa y uso la función reverse() pero no afecta la vista. Debo cambiar el archivo y guardarlo, luego puedo ver los cambios.

Artículos.js:

 import { useState } from "react"; const Items = (props) => { const [myArray, setMyArray] = useState([ { pId: 1, title: "P 1", }, { pId: 2, title: "P 2", }, { pId: 3, title: "P 3", }, { pId: 4, title: "P 4", }, ]); const handleSort = () => { console.log("before", myArray); setTimeout(() => { setMyArray(myArray.reverse()); console.log("after", myArray); }, 500); }; return ( <div> {myArray.map((a) => ( <span key={a.pId} className="m-3"> {a.title} </span> ))} <button onClick={handleSort}>reverse</button> </div> ); }; export default Items;

ingrese la descripción de la imagen aquí ingrese la descripción de la imagen aquí

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

0

Estás invirtiendo una matriz de objetos. use el operador de propagación para distribuir los elementos de su matriz.

Esto debería funcionar bien.

 let myArray = [ { pId: 1, title: "P 1", }, { pId: 2, title: "P 2", }, { pId: 3, title: "P 3", }, { pId: 4, title: "P 4", } ] console.log([...myArray].reverse());

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!