Unable to import Html5 Navigator #11013
-
Bug reportDescribe the bugI'm unable to use Navigator, I'm getting:
To ReproduceSimple try to use native HTML5 navigator api. Expected behaviorBe able to access navigator System information
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
Hi, you need to wrap any usage of client-side APIs in a |
Beta Was this translation helpful? Give feedback.
-
Thanks @ijjk, that make sense. |
Beta Was this translation helpful? Give feedback.
-
hello folks, I installed the library called device-uuid after that i started getting the navigator error after running build but before that I was not getting any build error , I have used navigator for making a functionality of copy to clipboard where i used navigator object I tried @ijjk solution but seems like it did not work ! Piece of code I tried after @ijjk solution
|
Beta Was this translation helpful? Give feedback.
-
If you are encountering issues even after following the Define a lazy-loaded component that encapsulates the implementation of the library depending on the window or navigator reference. In this example, I'm using the HandsontableJs library, which causes this behavior: import React from "react";
import { HotTable } from "@handsontable/react";
import "handsontable/dist/handsontable.full.min.css";
import { registerAllModules } from "handsontable/registry";
registerAllModules();
export default function Spreadsheets() {
return (
<HotTable
data={[
["", "Tesla", "Volvo", "Toyota", "Ford"],
["2019", 10, 11, 12, 13],
["2020", 20, 11, 14, 13],
["2021", 30, 15, 12, 13],
]}
rowHeaders={true}
colHeaders={true}
height="auto"
licenseKey="non-commercial-and-evaluation" // for non-commercial use only
/>
);
} Dynamically import the above component in your page component in next js as follows import dynamic from "next/dynamic";
const Spreadsheets = dynamic(
() => import("~/components/Spreadsheets/Spreadsheets"),
{
ssr: false,
}
);
export default function PageComponent() {
return <Spreadsheets />
} by doing this next js will only import your component only when the hydration took place which is in the browser where the window and the navigator is accessible for the component to use |
Beta Was this translation helpful? Give feedback.
Hi, you need to wrap any usage of client-side APIs in a
if (typeof window !== 'undefined')
check before you attempt to use them or else they will throw an error during SSR or prerendering