Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何在React函数中接收组件属性旁边的事件对象?_Reactjs_Event Handling - Fatal编程技术网

Reactjs 如何在React函数中接收组件属性旁边的事件对象?

Reactjs 如何在React函数中接收组件属性旁边的事件对象?,reactjs,event-handling,Reactjs,Event Handling,给定对激活函数的任何窗体的onSubmit事件调用,如何接收事件对象和其他属性 示例: const handleSubmit = async ( // EVENT OBJECT // OTHER PROPS THAT WILL BE PASSED TO 'userData' ) => { event.preventDefault() const userData = { firstName, lastName,

给定对激活函数的任何窗体的onSubmit事件调用,如何接收事件对象和其他属性

示例:

    const handleSubmit = async (
    // EVENT OBJECT
    // OTHER PROPS THAT WILL BE PASSED TO '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)
    }
  }
观察:

    const handleSubmit = async (
    // EVENT OBJECT
    // OTHER PROPS THAT WILL BE PASSED TO '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)
    }
  }
我试图通过事件和我的道具的分解,但它不起作用:

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