I am encountering an issue where the contents of local Storage are not being displayed until I manually refresh the page after clicking the submit button. How can I make it so that the changes made in local Storage immediately reflect on the page without needing to refresh?
The function responsible for handling page load seems to be showing incorrect data when a button is clicked. Only by manually refreshing the page, the correct data becomes visible.
const loadData = () =>
document.querySelector('body').addEventListener('load', displayStorage());
The event listener for saving:
notesForm.addEventListener('submit', e => {
e.preventDefault();
const save = (sid, spost, sdate) => {
const obj = { id: sid, post: spost, date: sdate };
localStorage.setItem(`${sid}`, JSON.stringify(obj));
};
save(generateId(), post.value, dateFormat());
loadData();
});