koblas / react-amplitude-hooks

Amplitude React components supporting hooks
MIT License
27 stars 8 forks source link

nextjs example? #21

Closed Enigma10 closed 2 years ago

Enigma10 commented 3 years ago

I am getting a warning that the amplitude instance is required. But it will be always undefined for server ride rendering.

koblas commented 3 years ago

I'm not sure what your issue is. If you don't have amplitude on the server side then it doesn't make sense to use this.

jeremyisatrecharm commented 3 years ago

I am also getting this error. I think the issue is Next.js compiles components' code for a "server" pass through and then again for client; and client-specific libraries expect window. I get this error:

Server Error
ReferenceError: window is not defined

This error happened while generating the page. Any console logs will be displayed in the terminal window.
Call Stack
<unknown>
[REDACTED]/node_modules/amplitude-js/amplitude.umd.js (1197:12)

I found a StackOverflow thread that discusses solutions and work arounds.