简体   繁体   中英

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?

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.

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);
    });
  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM