Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When trying to use useDymoCheckService I get "Uncaught Error: Invalid hook call." #41

Open
etorsuarezm opened this issue Jan 25, 2023 · 7 comments
Assignees
Labels
bug Something isn't working hacktoberfest https://hacktoberfest.digitalocean.com/

Comments

@etorsuarezm
Copy link

etorsuarezm commented Jan 25, 2023

Hi, there seems to be an issue with useDymoCheckService()

When trying to use it it throws an error.

`Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:

  1. You might have mismatching versions of React and the renderer (such as React DOM)
  2. You might be breaking the Rules of Hooks
  3. You might have more than one copy of React in the same app
    See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.`

This is pretty simple to reproduce.
1.- Start a new react project
npx create-react-app dymo-demo
2.- cd dymo-demo/
3.- npm install react-dymo-hooks
4.- Open the code and in App.js simply call the useDymoCheckService() method like so...

App_js_—_dymo-demo

5.- npm start

Result
Blank screen with the error in the console. Following the debugger is pointing at this part of the code..

React_App

My package.json looks like this...

{
"name": "dymo-demo",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-dymo-hooks": "^2.0.2",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}

@apenab
Copy link
Owner

apenab commented Jan 26, 2023

Hi, thx for the report, I´ll try to fix the error ASAP

@apenab apenab self-assigned this Jan 26, 2023
@apenab apenab added the bug Something isn't working label Jan 26, 2023
@umangcodes
Copy link

I have had this issue many times before. There is a simple solution.

This library depends on an older version of react and react-dom. You need to go inside the dependency tree of the library and then modify the package.json to link the library to the main project's react current version.

This should resolve the issue. The commands can be found online (npm link).

PS. @apenab Thanks for creating this package! Extremely useful!

@apenab apenab added the hacktoberfest https://hacktoberfest.digitalocean.com/ label Sep 29, 2023
@0llamh
Copy link

0llamh commented Feb 13, 2024

I ran into this issue specifically in my local environment, but on either my staging or production server. It was driving me insane. After a bunch of research, I was able to resolve this issue following this walkthrough:
https://stackoverflow.com/a/57422196

No peerDependency. No reverting versions of react (this wasn't an option for me anyway).

I ran yarn link in my virtual environment terminal in both my react\ and react-dom\ directories in my node_modules\ and finally ran yarn link react and yarn link react-dom in the react-dymo-hooks\ directory in the same node_modules\

Hope this helps other developers.

@bertrandyvernault
Copy link

I run into the same error when I upgrade my app to react 18.

To help futur people, the easiest way to fix it is to overrides in your packages.json the react and react-dom version used by the lib

This way with :

"overrides": {
  "react-dymp-hooks": {
    "react": "18.3.1",
    "react-dom": "18?3?1
  }
}

Be careful, this is the way of overrides if you use npm. If you are using yarn, i think it's resolutions.

I hope this helps too.

@hxk1633
Copy link

hxk1633 commented Oct 18, 2024

Has this issue been fixed? I tried what @0llamh and @bertrandyvernault suggested, but it still gives me the same error. I'm using Vite v5.4.9 if that helps.

@hxk1633
Copy link

hxk1633 commented Oct 28, 2024

Nevermind, I was able to fix it by doing what @0llamh found. It looks like I need to do this every time I install new package. This can get very annoying. Can this issue be fixed so we don't have to do this?

@bertrandyvernault
Copy link

My solution didn't work for you ? Be careful, if you are using yarn, the writing is different.

Don't forget to clean your .lock and node-modules.

I think to clean this, need to move the react dependency to peerDependencies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hacktoberfest https://hacktoberfest.digitalocean.com/
Projects
None yet
Development

No branches or pull requests

6 participants