I'm making a table with React, where the user can add new entries, and I'm deciding what to use as a key. I'm considering these options:
- Use database id. But this will force me to talk with the server every time the user wants to add a new entry, which is not ideal.
- Generate a front-end id for each row and persist it in the state
Option 2 clearly seems better, but I see the React docs recommend using database id.
I've dealt with this same dilemma many times over different projects, and I've never figured out the best solution, so I decided to get it answered once and for all.