saltyshiomix / nextron

⚡ Next.js + Electron ⚡
https://npm.im/nextron
MIT License
3.97k stars 229 forks source link

How can I use the window object from renderer ? #192

Closed Psycokwet closed 3 years ago

Psycokwet commented 3 years ago

I have discovered that by using a preload.js file, we could use the window object. Here, I set up an alert that load on the loading of the document

image Here ie my preload.js

document.addEventListener("DOMContentLoaded", () => {
  document.body.style.backgroundColor = "rgba(99, 99, 99, 1)";
  console.log(window);
  window.alert("ah que cc<s");
});

The problem is, I need the window object in my react code, not here. I need it to load a webview, or anything that could allows me to load a lib which need the window object as well.

How could I make the window object available anywhere in my renderer ?

This trick is the most I succeeded to do, it's been a while since I've been trying pretty much anything I could to import this lib, unsuccessfully.

Thank you for your attention.

If anyone could suggest an easy to use SIP <=> PSTN lib usable with nextron, I take it too. The one I have is easy to use with vanilla electron, and certainly vanilla react, but with the configuration of Nextron, I can't find a way to use it. But I'm certainly missing something here.

Psycokwet commented 3 years ago

By updating next, I have now access to the window object !

Updated by : yarn add -DE next react react-dom

Fixed the non component error by

module.exports = {
  webpack5: false,
  webpack: (config) => {
    return config;
  }
}

in next.config.js:

Credit to @hypernova7 that helped me in another issue !