WordPress 6.1.1 comes with React 17 but @wordpress/element requires React 18

[ad_1]

Hi! I have a clean install of WordPress 6.1.1 where I want to use Gutenberg blocks with React and I’ve noticed it comes with React 17 [https://prnt.sc/bVKB5VlSle5O])
In the network tab I can see it loads React 17.0.1 [https://prnt.sc/fLzoppgb-8FI])

Because of this, I can’t use React hooks like `useState` from `@wordpress/element` because it throws this error [https://reactjs.org/docs/error-decoder.html/?invariant=321])
After some digging, I found out `@wordpress/element` requires React 18.2.0 [https://prnt.sc/H3r1ekNT3bV9])

I’ve also tried debugging by using the methods from Duplicate React and indeed it prints false: [https://reactjs.org/warnings/invalid-hook-call-warning.html])

`npm ls react` shows this:
[https://prnt.sc/ussfpbTQeCf6])

Can I upgrade WP to React 18? I can’t see any `package.json` in the wp-includes folder.

So…I really don’t know what’s going on, any help would be appreciated, thank you!

[ad_2]
1 Comment

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer