I have an array of appointments and a react view that would display them one at a time. The user can browse the appointments by clicking arrows back and forward.
The data looks something like this:
const arr = [
{ start: 10, end: 12, id: 7532 },
{ start: 11, end: 13, id: 6775 },
{ start: 14, end: 15, id: 554 },
{ start: 17, end: 18, id: 3232 }
];
I'm trying to figure out what is the best way to implement this. The page displays the first element immediately and ideally, the user wouldn't be able to click the back button when the selected element is arr[0]. Same would apply to clicking forward. I'm a bit confused how indexing of arrays works in situations like this, I seem to get index value of -1 even when the selected appointment is part of the array. Also, I'm unsure if it makes sense to save the current index into a react state or just keep it in the function that is triggered on click.