-2

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

4
  • 2
    (event, props) => { ... } javascript.info/arrow-functions-basics Commented Mar 11, 2021 at 20:21
  • 2
    Only 1-argument functions can lack the () Commented Mar 11, 2021 at 20:21
  • 3
    Questions like this are often answered by a google search like "mdn arrow function" Commented Mar 11, 2021 at 20:21
  • 1
    Sorry guys for asking this question - as I said it will be a dumb one and yes, I saw the mdn webpage but did not understand it. Anyhow thanks for the anwers, it works now. Commented Mar 11, 2021 at 20:33

1 Answer 1

1

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

const changeLocationHandler = async (event, arg2, arg3) => {
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.