nashaofu / screenshots

A screenshot plugin for electron and react
https://nashaofu.github.io/screenshots/
MIT License
393 stars 99 forks source link

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

Closed Chandan-TY closed 1 year ago

Chandan-TY commented 1 year ago

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:

Chandan-TY commented 1 year ago

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

nashaofu commented 1 year ago

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()
  }
})
Chandan-TY commented 1 year ago

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.