WebStorm 2019.1 EAP #4: Extract method for React hooks, Convert to async function

WebStorm 2019.1 Early Preview build #4 is now available!

If you’re unfamiliar with our Early Access Program or if you want to catch up on all the new features, check out the previous EAP blog posts.

Toolbox App is the easiest way to get EAP builds. You can also get notified right from the IDE when a new EAP build is available: go to Preferences | Appearance & Behavior | System Settings | Updates and select “Automatically check updates for Early Access Program”.

DOWNLOAD WEBSTORM 2019.1 EAP

Important! WebStorm EAP builds are not fully tested and might be unstable.

Here are some of the highlights of WebStorm 2019.1 EAP #4 (build 191.5532.37). For the full list of issues fixed in this update, see the Release Notes.

Convert Promise to async/await

With this new intention in the IDE, you can automatically change a function that returns a promise with .then() and .catch() calls to an async function that uses the async/await syntax – not only in TypeScript files, but also in JavaScript and Flow.

Simply press Alt-Enter on the name of the function and select Convert to async function. Voila!

convert-to-async


WebStorm will introduce a new variable and replace Promise.catch with the try-catch block:

In this example, WebStorm knows that fetch returns a promise and suggests converting the download function to async:

Extract Method now works for custom React Hooks

React Hooks have recently landed in the stable React version. One of the features that was immediately suggested to us was a refactoring for creating a custom React hook – and the Extract Method refactoring is perfect for this task!

We’ve implemented a couple of improvements, namely, allowed Extract Method to work with local functions and use destructuring for the return values.

extract-react-hook

So here’s how it works:

  • Select the code you want to extract.
  • Use Refactor this… (Ctrl-T on macOS or Ctrl+Shift+Alt+T on Windows and Linux) or Extract Method (Alt-Cmd-M / Ctrl+Alt+M).
  • Select the scope where the extracted function should be defined.
  • Name it.

Flow integration now uses Flow LSP

We have re-implemented the IDE integration with Flow to use the Flow LSP APIs instead of the Flow server. This should not have any impact on your overall experience with Flow in WebStorm, but we hope that in the longer term, these Flow APIs will be more stable and evolved compared to the ones used before.

If you experience any new problems with WebStorm’s support for Flow, please let us know and report new issues on our tracker.

Update: we have received some complaints about the performance of the new integration and decided to disable in it WebStorm 2019.1. We continue working on it and plan to enable it in one of the upcoming bug-fix updates for WebStorm 2019.1.

Convert properties in constructor to class fields

With this handy new intention (Alt-Enter), you can replace properties defined in a constructor with class fields.

declare-class-fields

Soft-wraps for selected file types

You can now enable soft-wraps in the editor for specific file types. To do that, open Preferences/Settings | Editor | General and specify the file types in the “Soft-wrap files” field:

soft-wraps

With the soft wapping on, the IDE will display long lines wrapped in the editor without actually adding line breaks.

Please report any issues on our issue tracker. And stay tuned for the next week’s update!

WebStorm Team

About Ekaterina Prigara

Ekaterina Prigara is WebStorm product marketing manager at JetBrains. She's passionate about new technologies, UX and coffee.
This entry was posted in Early Access Preview and tagged , , . Bookmark the permalink.

4 Responses to WebStorm 2019.1 EAP #4: Extract method for React hooks, Convert to async function

  1. Asif Amin says:

    Nativescript support in Webstorm?

    https://www.nativescript.org/

  2. I could have sworn I saw an option in an early EAP that was directly title “Extract React Hook” that was a couple steps shorter than what exists in “Extract Function” as described in this article (to create a React Hook).

    Was I dreaming WebStorm features?

    • Ekaterina Prigara says:

      We have improved the Extract Method refactoring so that it works better for extracting React Hooks. We don’t have any dedicated refactoring for that.

Leave a Reply

Your email address will not be published. Required fields are marked *