score:2

data is an object already, if you put it inside a nested objet (body in this case) the map function of the encode method returns "object&object" because is an object.

you need to eliminate the body property inside the fetch function and spread the data objet in order to be iterable for the encode function.

change this:

fetch('/', {
        method: 'post',
        headers: { 'content-type': 'application/x-www-form-urlencoded' },
        body: encode({
            'form-name': 'react-validation-form',
            body: data,
        }),
    })

for this

fetch('/', {
        method: 'post',
        headers: { 'content-type': 'application/x-www-form-urlencoded' },
        body: encode({
            'form-name': 'react-validation-form',
            ...data,
        }),

Related Query

More Query from same tag