When creating a block for the WordPress block editor (a.k.a. Gutenberg), I find that most of the documentation is for class components. However, with React hooks we can use functional components.
When you need to import useState from react, you can do it as follows in a WordPress block.
const {
element: {
useState,
},
} = wp;
After this line useState is available for use.
I keep getting an error when I try to use useState – I get it in both a plugin and a theme. Have you come across this? I can’t find a way around it.
Error: Uncaught (in promise) Error: Minified React error #321; visit https://reactjs.org/docs/error-decoder.html?invariant=321 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
Same here. It borks the post if you save it. I can’t find much of any information regarding this.
https://github.com/WordPress/gutenberg/issues/16843