FormData Returns empty data on form submission in react
I think you need to fetch it through looping. Try this
var formData = new FormData(target);
for (var [key, value] of formData.entries()) {
console.log(key, value);
}
Hope it works.
handleSubmit should be like this.
handleSubmit(event) {
event.preventDefault();
const data = new FormData(event.target);
fetch('my-api', {
method: 'POST',
body: data,
});
}
After form submit, in network tab you will find form data with key-value.
If you want to access single value,
const username = data.get('username');