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

145
Views
React.memo is not working on state change

When I click an item for change only this state value. But then re-render rest item, although I use memo. How to prevent re-render rest items.

App.js

const App= ()=> {
  const [items, setItems] = useState({
   [`item-1`]: {
     h: 100,
     w: 100
  },
  [`item-2`]: {
     h: 200,
     w: 200
  }
  const changeProp = (d)=>{
   const getElement = d.currentTarget;
   const itemKey = getElement.getAttribute('data-key');

   const deepCopy = JSON.parse(JSON.stringify(items));
   deepCopy.[itemKey] ={
        h: rect.height,
        w: rect.width,
   }
   setItems(deepCopy);
  }
  const getItems = Object.entries(items);
  return (
    <div>
      { getItems.map( (d,i) => <Item data={d} key={i} changeProp={changeProp}/> ) }
    </div>
  );
}

Item.js

const Item = ({data, changeProp}) => {
 return (
        <div className="eachItem" id={getKey} data-key={getKey} onClick={e=>changeProp(e)}>
            item
        </div>
    );
}
export default memo(Item);

about 4 years ago · Juan Pablo Isaza
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!