'ReferenceError: window is not defined' for ConnectButton example in React/Next.js app

The ConnectButton example in the documentation (Using the framewok module - Ceramic Developers) for a React app works on the first load, but subsequent page loads produce an error ‘ReferenceError: window is not defined’, presumably, because the code is executed server-side where “window” is undefined.
In other situations, the use of React’s “useEffect()” function can be leveraged to force code to execute in the browser, but I don’t know how to apply this to the button. Can others verify that the example code from the docs works as intended or did you have to make adjustments to avoid this problem?

Thanks for any help!


These code examples are meant to be very simple and assume the code is running in a browser environment, you should adapt to your needs and the specifics of your framework/environment if it’s not the case.

Yep. On that learning journey now. Are you aware of any other projects using Next.js to build on ceramic? I’ll be happy to post my code once its working.

Yes we’re using Next.js for the self.id app, see self.id/apps/self.id at main · ceramicstudio/self.id · GitHub

1 Like