I’m on the web dev learning journey. Most recently I’ve been learning React Router and I’m excited to be close to building my first full stack (MERN) apps! The vast majority of the tutorials I’ve done have been within the Codecademy website but I decided to go outside of it for React Router since the Codecademy version is out of date.
Anyhow, I’m quite confused on an aspect of this tutorial: Tutorial v6.6.2 | React Router. Specifically, I’m confused about code in the contacts.js file (essentially it’s emulating database queries by using localStorage…or rather a package called localForage which uses localStorage). Anyhow, here is this particular module:
I might be missing something obvious but I don’t understand how the updateContact function is actually accomplishing anything that persists the updated data into local storage…For more context, here is the section of the tutorial in which updateContact is called: Tutorial v6.6.2 | React Router. From my perspective, the form data is submitted, the action function is called (editAction if you’re looking at main.jsx), we turn the form data into an object, we call updateContact, and we redirect, etc. The app does work, somehow, which leads me to believe I’m missing something, but what’s strange is inserting console.log(contacts) or even console.log(contact) before Object.assign results in the updated contact data actually being logged. Regardless, I’m confused because we never make an update to the actual contacts array, as far as I can tell, before calling the set function and the only update to the contact object should just be lost to the ether since it’s never persisted anywhere? Or am I totally missing something here?
Sorry that this is off-site, but I feel most comfortable asking this here since I’ve used Codecademy as my primary learning website. I would appreciate any help here but I understand if going off-site is necessary to get an answer (though unfortunately React Router doesn’t have any forums as far as I can tell).