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

146
Views
Component List do no re render when having key

I have an array of strings that look like this

['sass', 'css', 'daniel', 'javascript', 'figma', 'html', 'git', 'react', 'blank']

It is in state and I pass the array to a child component as props, to iterate it and create a list, that is displayed inside a board of items

[ 1 , 2 , 3]

[ 4 , 5 , 6]

[ 7 , 8 , 9]

. When I click a button the array is mixed up with the same elements and passed again to props

const SlidePuzzle = ({puzzleItems}) => {
return (
    <div className="slidePuzzleContainer">
        {puzzleItems.map((item, index) => {
            return <PuzzleItem item={item}  key={index} />;
        })}
    </div>
)};

I thought the list of items was not re rendering when props changed. But they were indeed, and changed their order in the DOM. Just that they kept their previous position in the board. I solve this by removing the key or setting it to the index of the array (that I know is not the best). Could you please explain why this happens and if there's a better way to solve this ? Thank you so much..... :)

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!