DEV Community

loading...

Discussion on: React - how to create dynamic table

Collapse
wearypossum4770 profile image
Stephen Smith

The code has a bug. It assumes the objects are sorted by "id." I introduced a bug by switching "id" values.

Collapse
wearypossum4770 profile image
Stephen Smith

How about this suggestion? It fixes the "bug" I introduced.

...
 students.sort((a,b) => a.id-b.id).map(({ id, name, age, favFruit }) => 
...
Enter fullscreen mode Exit fullscreen mode