-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
global
variable in browser context is always undefined. I think you meant globalThis
#91
Comments
yes, i am facing the same issue. As soon i use the hook, my app crashes with an error The error goes away if i put |
facing same problem now created custom solution using |
I solved this by adding Example: import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import './index.css';
window.global = globalThis;
ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<App />
</React.StrictMode>
); |
This will also work: import useDarkMode from "use-dark-mode";
import { Switch } from "@nextui-org/react";
import { SVGProps } from "react";
export const ThemeSwitcher = () => {
const darkMode = useDarkMode(false, {
classNameDark: "dark",
classNameLight: "light",
global: window, // Just pass this as a config option
});
return (
<Switch
defaultSelected={darkMode.value}
onValueChange={darkMode.toggle}
size="lg"
color="warning"
startContent={<MoonIcon />}
endContent={<SunIcon />}
/>
);
}; |
use-dark-mode/src/initialize.js
Line 15 in 2959027
The global variable will only exist in node during ssr.
globalThis
===window
in browsers andglobalThis
===global
in nodeThe text was updated successfully, but these errors were encountered: