score:2

Accepted answer

the count is not is not sorted. it just got updated when you sorted.

keys help react identify which items have changed, are added, or are removed. keys should be given to the elements inside the array to give the elements a stable identity

every time you sort, key stay the same, as you use count.

try using value as key

export function parent(){
  // ....
  return (
      <div>
          <button onclick={handlesort}>sort</button>
          {children.map(child => {
            return <childcomp key={child.value} details={child}/> // key is important
          })}
      </div>
  )
}

more info: https://reactjs.org/docs/lists-and-keys.html#keys


Related Query

More Query from same tag