I am trying to develop a custom gutenberg block. I have a form in save.js:
export default function save() { return ( <div {...useBlockProps.save()}> <form onSubmit={handleSubmit}></form> </div>);}
File view.js is defined in block.json ("viewScript": "file:./view.js",)
const handleSubmit = async (event) => { event.preventDefault(); const formData = new FormData(event.target); ... };
But when the block renders, it fails.
Uncaught ReferenceError: handleSubmit is not defined
Its all nice if i use "traditional" javascript (e.g. jQuery, console.log), so enqueueing is not the problem. I am pretty new with "modern" javascript (React, Angular...) and the question is surely pretty dumb, but i am looking for a proper way to coding and not only looking for a functional solution.
export
in view.js to export handleSubmitexport const handleSubmit = async (event) => {
then import handleSubmit in the beginning of save.js pageimport { handleSubmit } from './save';