DEV Community

Discussion on: POST FormData to JSON object array with ReacStrap Form and Express

Collapse
 
jamesthomson profile image
James Thomson

The reason you get the error

Uncaught TypeError: Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'.

is because the parameter it expects is a form element.

I can see you have const form = useRef(null);, but I can't see anywhere that you actually set that reference to your form. You need to use forwardRef in your WebForm component to target the form.

This way you can them put a ref on your component to gain access to the form element nested within it. Assuming you've forwarded the ref, you can then write <WebForm ref={form} ... /> which should then ensure your submit function gets all the form data when submitting to your endpoint.