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

289
Views
Error al representar una matriz ordenada en next.js

Estoy tratando de representar una serie de elementos en función de su valor (de mayor a menor). Todo funciona bien, pero recibo un error que dice Error: Text content does not match server-rendered HTML. cada vez que ejecuto el código. A continuación se muestra el código utilizado para clasificar los items de la matriz y mapear cada elemento en función de su valor. No estoy seguro de cómo evitar este error.

 const items = [ {id: 1, title: 'Topic 1', value: 2}, {id: 2, title: 'Topic 2', value: 5}, {id: 3, title: 'Topic 3', value: 1}, {id: 4, title: 'Topic 4', value: 4}, {id: 5, title: 'Topic 5', value: 3}, ] const App = () => { <div className="flex flex-col gap-4 w-full p-6 items-center"> {items.sort((a, b) => b.value - a.value).map((item, index) => ( <div className="flex gap-2 px-4 items-center h-10 w-full rounded-md text-lg bg-[#ffd700]" key={index} > <div> {item.title} {item.value} </div> /5 </div> ))} </div> }
about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

Para cualquier futuro lector; el error se puede solucionar simplemente incluyendo la lista de lo que sea que esté tratando de ordenar dentro de la función principal.

Por ejemplo:

 const App = () => { const items = [ {id: 1, title: 'Topic 1', value: 2}, {id: 2, title: 'Topic 2', value: 5}, {id: 3, title: 'Topic 3', value: 1}, {id: 4, title: 'Topic 4', value: 4}, {id: 5, title: 'Topic 5', value: 3}, ] <div className="flex flex-col gap-4 w-full p-6 items-center"> {items.sort((a, b) => b.value - a.value).map((item, index) => ( <div className="flex gap-2 px-4 items-center h-10 w-full rounded-md text-lg bg-[#ffd700]" key={index} > <div> {item.title} {item.value} </div> /5 </div> ))} </div> }
about 4 years ago · Santiago Gelvez Report

0

Creo que este error se debe al hecho de que está utilizando ( en lugar de { en la función .map . La sintaxis correcta de la función .map es:

 items.map((item, index) => { return <>...</> })

Su ejemplo funcionaría con esto:

 const items = [ {id: 1, title: 'Topic 1', value: 2}, {id: 2, title: 'Topic 2', value: 5}, {id: 3, title: 'Topic 3', value: 1}, {id: 4, title: 'Topic 4', value: 4}, {id: 5, title: 'Topic 5', value: 3}, ] <div className="flex flex-col gap-4 w-full p-6 items-center"> {items.sort((a, b) => b.value - a.value).map((item, index) => { <div className="flex gap-2 px-4 items-center h-10 w-full rounded-md text-lg bg-[#ffd700]" key={index} > <div> {item.title} {item.value} </div> /5 </div> })} </div>
about 4 years ago · Santiago Gelvez 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!