Closed ivopaunov closed 6 months ago
if the useEffect does not work try something like this but it's not the best solution as it can be used for other stuff
useEffect(() => {
window.onbeforeunload = function() {
updateCampaign((prev) => {
updateCampaignPersist(prev)
return prev
})
}
return true;
}
return () => {
window.onbeforeunload = null
}
}, [])
try localStorage.setItem
/ localStorage.getItem
if useLocalStorage does not wotk in window.onbeforeunload
Currently the state managmet of the campaign vreation makes no sense. It uses localStorage to keep and update the state on each user input interaction. The esiest way to be fixed is as follows:
create-campaign
route (keep in mind some sensitive dtata if the user is not different or not authenticated - dashbourd route should be ok + some check on logout etc.. At the moment current create campaign datat is not linked to specific user and if there user is not loggged/authenicated)useState
insteaduseLocalStorage
for campaign object - this way the state will be kept intil the page is reloaded and the user in dashboard routeuseLocalStorage
+ useEffect in which to update theuseState
object on component mount ([] - empty array for the use efffect update deps) with callback (similar to componen will unmout) to write the the object in the localStoragethis way the local storage will not be updated on each key press etc.