Encountering the issue
ReferenceError: localStorage is not defined
when attempting to deploy my Next.JS app on Vercel.
const NewReserve: React.FC = () => {
const setValue = (key: string, value: string) => {
return localStorage.setItem(key, value);
};
const getValue = (key: string) => {
return JSON.stringify(localStorage.getItem(key));
};
const returnPersistentValue = (key: string) => {
if (getValue(key) === "null") return "";
else return getValue(key).replace('"', "").replace('"', "");
};
...
The reason for this error is likely due to the fact that Vercel's deployment system operates on the server-side, causing both window and localStorage to be undefined, resulting in the reference error. How can I go about resolving this issue?