Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expected to return a value at the end of arrow function with if statement

I am having this code.

{
  Object.keys(_.get(order, "customer", {})).map((key) => {
    if (key !== "defaultOption" && customer[key] !== "") {
      return (
        <option key={key} value={key}>
          {_.startCase(key)}
        </option>
      );
    }
  });
}

And having below warning

  Line 885:96:  Expected to return a value at the end of arrow function  array-callback-return

I know because I am using if statement inside the map function. So, How to get rid of the error?

like image 304
Dark Knight Avatar asked Dec 17 '22 13:12

Dark Knight


1 Answers

return something after the if statement (even if it is an empty string).

You might want to filter such values out of the array afterwards (or just filter the array first instead of using an if).

like image 116
Quentin Avatar answered Dec 31 '22 03:12

Quentin