Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
If I have a useState which has a value of 4, how can I use the below function to create the returned HTML 4 times using the value? (React)

I am trying to create a quiz app which at the end of each round creates a table which contains the players score as well as the score of a set number of random players. Lets say the number of random players has been pre selected and is 4. How do I use the value of 4 from the useState to render the below HTML 4 times? I couldn't get for loop to work, maybe someone else can or has another idea?

    function Players () {
      
      return <><tbody>
      <tr>
        <td>{teamName}</td>
        <td class="space"></td>
        <td>{score}</td>
      </tr>
    </tbody></>
    }
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can create an array of desired length using Array.from and fill it with the Players component and then render the array.

function App() {
  const [count, setCount] = useState(4);

  return (
    <div>
      {Array.from({ length: count }, () => (
        <Players />
      ))}
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

you can use Array constructor to do this.

Code:

const [number, setNumber] = useState(4);

{
   [...Array(number)].map((_, index) => (
    <div className="" key={index}> Whatever needs to be repeatedly </div>
       )
    )
 }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda