React 18 causing invalid hook call error, downgrading to React 17 and wiping node_modules resolves issue
33 replies
Last updated: Jun 3, 2022
M
Sanity is freaking out
Jun 3, 2022, 5:36 PM
M
It was working till yesterday
Jun 3, 2022, 5:43 PM
M
Suddenly started freaking out
Jun 3, 2022, 5:43 PM
M
It just warns me about React 18
Jun 3, 2022, 5:43 PM
M
and says to degrade
Jun 3, 2022, 5:43 PM
M
Please help me
user M
it's urgent I have to complete the project within few hoursJun 3, 2022, 5:51 PM
M
Is it necessary to downgrade
Jun 3, 2022, 5:52 PM
M
I mean downgrading isn't a good practice
Jun 3, 2022, 5:53 PM
M
user A
Do I have to degrade the whole project or only the studio directory to React 17?Jun 3, 2022, 5:54 PM
M
It says invalid hook call
Jun 3, 2022, 5:57 PM
M
What kind of hook call am I making here?
Jun 3, 2022, 5:57 PM
M
I am just using default blog schema
Jun 3, 2022, 5:57 PM
M
It is a blog
Jun 3, 2022, 5:57 PM
The studio hasn’t been tested against React 18 yet, which is why it’s pegged at version 17. Can you first confirm whether or not you’re on React 18?
Jun 3, 2022, 5:58 PM
M
I am on React 18
Jun 3, 2022, 6:00 PM
M
So I should degrade to React 17?
Jun 3, 2022, 6:01 PM
M
Ok
Jun 3, 2022, 6:01 PM
M
Only degrade the studio or the whole project?
Jun 3, 2022, 6:02 PM
M
user A
Jun 3, 2022, 6:02 PM
M
My package.json
{ "name": "knutmelvaerno", "private": true, "version": "2.0.0", "description": "", "main": "package.json", "author": "Knut Melvær <knut.melvaer@gmail.com>", "license": "MIT", "scripts": { "start": "sanity start", "test": "sanity check" }, "keywords": [ "sanity" ], "dependencies": { "@sanity/base": "^2.30.1", "@sanity/components": "^2.14.0", "@sanity/core": "^2.30.1", "@sanity/default-layout": "^2.30.1", "@sanity/default-login": "^2.30.1", "@sanity/desk-tool": "^2.30.1", "prop-types": "^15.8.1", "react": "17.0.0", "sanity": "^2.29.3", "styled-components": "^5.3.5" } }
Jun 3, 2022, 6:02 PM
I can’t speak to your front end and whether it’ll work with React 18, but you’d want to revert your studio at the very least.
Jun 3, 2022, 6:04 PM
M
It still doesn't work
Jun 3, 2022, 6:07 PM
M
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://reactjs.org/link/invalid-hook-call> for tips about how to debug and fix this problem.
Jun 3, 2022, 6:07 PM
M
user A
Jun 3, 2022, 6:10 PM
M
I reverted everything to React 17
Jun 3, 2022, 6:10 PM
M
Doesn't work
Jun 3, 2022, 6:10 PM
Did you wipe your node_modules and re-install? You could have multiple versions of React still (reason 3 in the error).
Jun 3, 2022, 6:16 PM
M
Ok doing it
Jun 3, 2022, 6:17 PM
M
Works now
Jun 3, 2022, 6:22 PM
M
Thanks a lot
Jun 3, 2022, 6:22 PM
Sanity– build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.