How to receive the event object next to the props of a component in a React function?

Asked

Viewed 25 times

0

Given a call from event onSubmit in any form that activates a function, how can I receive the event object along with other properties?

demonstration:

    const handleSubmit = async (
    // OBJETO DE EVENTO
    // AS DEMAIS PROPRIEDADES QUE PASSEI PARA O 'userData'
  ) => {

    event.preventDefault()

    const userData = {
      firstName,
      lastName,
      username,
      email,
      ...(phone && { phone }),
      ...(mobilePhone && { mobilePhone }),
      password,
      confirmPassword,
      ...(expireDate && { expireDate }),
      status,
      profile,
      company
    }
    const parsedUserdata = new URLSearchParams(userData)

    try {
      await api.post('/users', parsedUserdata)
      window.location = '/users-list'
    } catch (error) {
      console.log(error)
    }
  }

REMARKS:

I’ve tried to pass the event and a breakdown of my props, but it doesn’t work:

const handleSubmit = async ( e, { firstname, lastName}) => {...}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.