add-to-homescreen-react
add-to-homescreen-react copied to clipboard
Window is not defined
After installation i tried to launch my project locally, but got error window is not defined
Hm, that is unfortunately very little information - too little to be able to investigate the problem. Can you possibly give more information? E.g. How exactly do you integrate add-to-homescreen-react
in your project? Can you provide the corresponding code snippet? Which module packer tool do you use? ...
BTW: You can find examples for integration and usage of the component within examples
folder of the add-to-homescreen-react
project. See https://github.com/as-ideas/add-to-homescreen-react#examples for details how to build and start them locally on your machine. Maybe these examples can help you with the integration of add-to-homescreen-react
.
Most likely it's because of SSR, where window
is not available.
That's right. Currently, this React component is not designed for SSR. I guess rendering it server-side doesn't make much sense either. For example, it needs information about the current platform (i.e. iOS, Android) it is running on, and also uses the local storage of the browser.
I had this issue as well on a Gatsby.js implementation. Using the loadable-components package ensured that it would only load on the client-side (and not break on SSR compilation).
import loadable from "@loadable/component";
const AddToHomeScreen = loadable(() => import('@ideasio/add-to-homescreen-react')