I'm mostly interested in useState
. It works fine in edit.js
, but in save.js
it just breaks and it throws the minified React error, see below:
I tried creating a separate .jsx
component file but it throws the error when it encounters useState()
. I tried importing it from both "react"
and "@wordpress/element"
packages.
The component looks like this, something basic:
Then I just imported it into save.js
in my custom block:
The Gutenberg plugin is installed, version 15.2.0.
save
attribute is supposed to take the block’s attributes and render static HTML that can be saved to the database. It doesn’t run on the front end and it shouldn’t contain any interactivity. If you want a React app on the front end you need a separate script on the front end that renders the app into that HTML.