1

I'm trying to add an if statement to a function and am getting syntax errors. Here's the original function test using the fat arrow syntax that works. I think I'm misunderstanding what the ( around the return object means in line 2. I'm used to seeing { but not sure what a ( means.

var foo = {
    test: (state, action) => (  // does this paranthesis create a block around the function? or does it mean something else?
      {
        isFetching: false,
      }
    )
}

However I get a syntax error when I try to add an if statement, what does the parenthesis mean in this case - is it declaring the body of a function declared with a fat arrow?

The following gives a syntax error:

var foo = {
    test: (state, action) => (
      if (action.payload) { 
        return { isFetching:false } ;
      } else {
        return { isFetching: true };
      }
    )
}
MonkeyBonkey
  • 46,433
  • 78
  • 254
  • 460

0 Answers0