I have a Next.js
app
This is one of my page/component looks like
import React from "react";
import { SomeLocalStorageComponent } from "some-external-lib";
const MyComponent = () => {
const isBrowser = typeof window !== "undefined"
{
if (isBrowser) {
<SomeLocalStorageComponent></SomeLocalStorageComponent>
}
}
};
export default MyComponent;
This is throwing the below run time error
Server Error
ReferenceError: localStorage is not defined
Here SomeLocalStorageComponent
is an external library component which is dependant on a localStorage
variable
When this SomeLocalStorageComponent
is used in a React app, it functions as expected however when I'm consuming this into Next.js app it throws the error.
how to get rid of this error?
Please suggest. Thanks!