Invalid Hook Call Warnings in Sanity Studio with React 18.2.0
This is a classic styled-components version mismatch issue! The problem is that you have styled-components 5.2.0, but @sanity/ui 1.3.1 requires styled-components 5.3.x or higher as a peer dependency.
When you have an incompatible version of styled-components, it can cause React to be bundled multiple times, which triggers the "Invalid hook call" warning you're seeing.
The Fix
Upgrade your styled-components to version 5.3.x or higher:
npm install styled-components@^5.3.0
# or
yarn add styled-components@^5.3.0After upgrading, delete your node_modules and lock file, then reinstall:
rm -rf node_modules package-lock.json
npm installThis should resolve all 50 warnings you're seeing.
Why This Happens
@sanity/ui (which Sanity Studio v3 depends on) uses styled-components internally and has strict peer dependency requirements. When the versions don't match, you can end up with:
- Multiple copies of React in your bundle
- Multiple copies of styled-components
- React hooks being called from different React instances, causing the invalid hook call error
The @sanity/ui documentation lists styled-components as a required peer dependency, and checking @sanity/ui@1.3.1's package.json confirms it needs styled-components ^5.3.0.
Additional Tips
If upgrading styled-components doesn't completely resolve it (especially with Next.js embedded Studio setups), you can also try:
Check for duplicate React versions by running:
npm ls reactAdd resolution/overrides to your package.json to force a single version:
"overrides": { "styled-components": "^5.3.0" }(or
"resolutions"if using Yarn)Consider upgrading to newer versions of the Sanity packages - you're on 3.8.3, and there have been many improvements since then.
The styled-components upgrade should fix your issue immediately though!
Show original thread27 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.