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

107
Views
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 answers
Answer question

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 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!