From 1a33c493e47f360f0ae246882b2e643f17ea7673 Mon Sep 17 00:00:00 2001 From: hiento09 <136591877+hiento09@users.noreply.github.com> Date: Mon, 9 Oct 2023 08:55:05 +0700 Subject: [PATCH] Fix Docusaurus server side render error (#301) Co-authored-by: Hien To --- docs/src/components/Elements/dropdown.js | 29 +++++++++++++----------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/docs/src/components/Elements/dropdown.js b/docs/src/components/Elements/dropdown.js index 4145f0fda..db40643d0 100644 --- a/docs/src/components/Elements/dropdown.js +++ b/docs/src/components/Elements/dropdown.js @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useState, useEffect } from "react"; import { Fragment } from "react"; import { Menu, Transition } from "@headlessui/react"; import { ChevronDownIcon } from "@heroicons/react/20/solid"; @@ -31,19 +31,22 @@ function classNames(...classes) { } export default function Dropdown() { - const uAgent = window.navigator.userAgent; - let defaultSystem; + const [defaultSystem, setDefaultSystem] = useState(systems[0]); - if (uAgent.indexOf("Win") !== -1) { - defaultSystem = systems[2]; - } else if (uAgent.indexOf("Mac") !== -1) { - // Note: There's no way to detect ARM architecture from browser. Hardcoding to M1/M2 for now. - defaultSystem = systems[0]; - } else if (uAgent.indexOf("Linux") !== -1) { - defaultSystem = systems[3]; - } else { - defaultSystem = systems[0]; - } + useEffect(() => { + const uAgent = window.navigator.userAgent; + + if (uAgent.indexOf("Win") !== -1) { + setDefaultSystem(systems[2]); + } else if (uAgent.indexOf("Mac") !== -1) { + // Note: There's no way to detect ARM architecture from browser. Hardcoding to M1/M2 for now. + setDefaultSystem(systems[0]); + } else if (uAgent.indexOf("Linux") !== -1) { + setDefaultSystem(systems[3]); + } else { + setDefaultSystem(systems[0]); + } + }, []); return (