1

I am using ESlint in my project. I am getting the error ** Unexpected block statement surrounding arrow body** from this function

const toggleDrawer = (state) => {
 return {
 ...state,
 drawerExpanded: !state.drawerExpanded,
 };
};

Can anyone suggest me how to handle this ESlint error?

scn
  • 45
  • 2
  • 9
  • See https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions#Returning_object_literals. –  Mar 30 '17 at 06:08
  • Possible duplicate of [ECMAScript6 arrow function that returns an object](http://stackoverflow.com/questions/28770415/ecmascript6-arrow-function-that-returns-an-object) –  Mar 30 '17 at 06:09
  • @torazaburo I checked that. It didn't help. – scn Mar 30 '17 at 14:24

1 Answers1

1

Wrap the object in parenthesis ()

const toggleDrawer = (state) => ({
 ...state,
 drawerExpanded: !state.drawerExpanded,
});

Also check if you have : arrow-body-style: ["error", "as-needed"] in es-lint

loganfsmyth
  • 156,129
  • 30
  • 331
  • 251
Nishanth Matha
  • 5,993
  • 2
  • 19
  • 28