Friday, 1 May 2020

Updating an array from react state through express api (mongodb)

Hey there! So I create a list of items and all of them are listed from newest to oldest by default when I create them.I then rearrange that array with React (React Beautiful DND) and that returns the new order in state. But the order is changed in the database. So if I refresh the page state is lost and I lose the new order.How would I update this new order in the database? Do I just send the entire new array to an /api/updateList route? or with something like with findOneAndUpdate. I just wonder if there is a best practice for updating items in an array. Because not every item in the array is changed so is it best to update the entire array or just an index?Any insight will be appreciated! Thanks in advance.Also note that I am return the exact format in state as the db. Its an array of objects with a few key value pairs.

Submitted May 01, 2020 at 07:30AM by drdaydreamv2

No comments:

Post a Comment