Search code examples
javascriptreactjsarrow-functions

How to add multiple parameters in arrow function


already sorry for my stupid question but googling for it was not successful

How can I add multiple parameters in an arrow functions. I want to add some properties "props" to the following function.

  const changeLocationHandler = async event => {
    try {
      let hasError = false;
      let response = await fetch('http://localhost:5000/api/game/location', {
        method: 'POST',
        headers: {
          Authorization: 'Bearer ' + auth.token
        },
        body: { 
        }
      });
      const responseData = await response.json();
      if (!response.ok) {
        hasError = true;
      }
      if (hasError) {
        alert(responseData.message);
      }  
    } catch (error) {
      alert(error)
    }
  }

It does not accept someting like

const changeLocationHandler = async event props => {

or

const changeLocationHandler = props => async event => {

Thanks in advance


Solution

  • You need to wrap the arguments in parentheses for this to work.

    const changeLocationHandler = async (event, arg2, arg3) => {