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

106
Vistas
i'm wanting onChange to keep generate id ReactJS

I have function makeid

const makeid = (length) => {
  var result = "";
  var characters =
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  var charactersLength = characters.length;
  for (var i = 0; i < length; i++) {
    result += characters.charAt(Math.floor(Math.random() * charactersLength));
  }
  return result;
};

and i have function createArray use makeid

const createArray = (x) => {
  let array = [];
  const object = {
    id: makeid(5),
  };
  for (let i = 1; i <= x; i++) {
    array.push(object);
  }
  return array;
};

& I create func nummberOfColumns

let a = [];
[...studentObject, ...createArray((5 -studentObject.length)].map((ele) => {
      a.push({
        id: ele.id,
        });
});
return a

then I use number Of Columns.map() to return the </th> tag. In this tag I use onChange, but every time onChange the id changes to another id, I don't want that to happen. I tried using Usememo but it didn't work.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Use useEffect with an empty dependencies array ([]). There, initiate all your code and attach the result to a state. You can use useState to manage that. It's happening because on each change in a tree, all the subtree re-renders. useEffect with an empty array only runs after mounting and first update (layout and paint). If you want to use useMemo, make sure to pass an empty array as well to prevent from re-calculation when a dependency changes.

useEffect(function(), [])

useMemo(function(), [])

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