Leo Messi
Leo Messi

Reputation: 6186

Unexpected block statement surrounding arrow body with ESLint

The following code has this warning in console:

Unexpected block statement surrounding arrow body; move the returned value immediately after the =` arrow-body-style

 blobToDataURL = blob => {
    return new Promise((resolve, reject) => {
      const reader = new FileReader();
      reader.onerror = reject;
      reader.onload = e => resolve(reader.result);
      reader.readAsDataURL(blob);
    });
  };

What does it mean?

Upvotes: 1

Views: 229

Answers (2)

Taki
Taki

Reputation: 17654

It wants you to use implicit return :

blobToDataURL = blob => 
     new Promise((resolve, reject) => {
      const reader = new FileReader();
      reader.onerror = reject;
      reader.onload = e => resolve(reader.result);
      reader.readAsDataURL(blob);
    });
  

Upvotes: 2

Quentin
Quentin

Reputation: 943649

Arrow functions can take one of two forms:

() => return_value;

and

() => {
    something;
    something;
    return return_value;
};

The warning you are getting is that you are using the second format even though you have only a single statement, which you are returning, so you can use the first form.

Upvotes: 4

Related Questions