nashaofu / screenshots

A screenshot plugin for electron and react

Home Page:https://nashaofu.github.io/screenshots/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Invalid hook call. You might have mismatching versions of React and the renderer

Chandan-TY opened this issue · comments

We are using React version 18.1.0 along with the electron app. While we tried installing electron-screenshots and using them. We are getting an Invalid hook call. You might have mismatching versions of React and the renderer.
I can see in node_modules\electron-screenshots\node_modules\react-screenshots the react version is 17.0.2. I think the issue is because of that. Let us know what is the fix for this issue.

image

Steps to reproduce the behavior:

  1. Create an electron app with react 18 version and versions as specified below
  2. Install electron-screenshots
  3. Run the app
  4. See the error

Expected behavior
Should support React version 18 also

image

Versions:

  • React :
    "react": "^18.1.0",
    "react-dom": "^18.1.0",
  • Electron: "electron": "^16.0.5",
  • electron-screenshots: "electron-screenshots": "^0.5.15",

@nashaofu
Could you please guide me on fixing the above issue

Do you have a recurrence code? Do you want to use the electric screenshot? Can the following code work normally?

import { app, globalShortcut } from 'electron'
import Screenshots from './screenshots'

app.whenReady().then(() => {
  const screenshots = new Screenshots()
  globalShortcut.register('ctrl+shift+a', () => {
    screenshots.startCapture()
  })
})

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

The issue is resolved after adding
alias: {
react: path.resolve('./node_modules/react'),
}
inside resolve object in webpack.config.js.
Anyway thanks for your quick response.