You can use the create-react-app package or create an empty PhpStorm project and install React in it.

Generating a React application with create-react-app

PhpStorm guarantees running and debugging Jest tests only with the react-scripts package.

Create React App is the recommended way to start building a new React single page application. As a result, your development environment is preconfigured to use webpack, Babel, ESLint, and other tools. Learn more about installing React and creating React applications from React Official website.

To get code completion for React methods and React-specific attributes, you need to have the react.js library file somewhere in your project. Usually the library is already in your node_modules folder.

Completing React methods, attributes, and events By default, the code completion popup is displayed automatically as you type. For example: In JSX tags, PhpStorm provides coding assistance for React-specific attributes, such as className or classID, and non-DOM attributes, such as key or ref. Moreover, autocompletion also works for names of classes defined in the project’s CSS files: All React events, such as onClick or onChange, can also be completed automatically together with curly braces (={}): Completion also works for JavaScript expressions inside curly braces. This applies to all the methods and functions that you have defined:

Completing HTML tags and component names PhpStorm provides code completion for HTML tags and component names that you have defined inside methods in JavaScript or inside other components: Completion also works for imported components with ES6 style syntax:

Completing component properties PhpStorm provides code completion for component properties defined using propTypes and resolves them so you can quickly jump or preview their definitions: When you autocomplete the name of a component, PhpStorm adds all its required properties automatically. If some of the required properties are missing in the usage of a component, PhpStorm warns you about that.

Transferring HTML attributes to JSX

When you copy a piece of HTML code with class attributes or on-event handlers and paste it into JSX, PhpStorm automatically replaces these attributes with React-specific ones (className, onClick, onChange, etc.)

Using Emmet in JSX

With PhpStorm, you can use Emmet not only in HTML but also in your JSX code taking advantage of some special React twists. For example, the abbreviation div.my-class expands in JSX to <div className=”my-class"></div> but not to <div class=”my-class"></div> as it would in HTML:

All the PhpStorm built-in code inspections for JavaScript and HTML also work in JSX code. PhpStorm alerts you in case of unused variables and functions, missing closing tags, missing statements, and much more: For some inspections PhpStorm provides quick-fixes, for example, suggests adding a missing method. To view the quick-fix pop-up, press Alt+Enter.

Using ESLint

Besides providing built-in code inspections, PhpStorm also integrates with linters, such as ESLint, for JSX code. ESLint brings a wide range of linting rules that can also be extended with plugins. PhpStorm shows warnings and errors reported by ESLint right in the editor, as you type. With ESLint, you can also use JavaScript Standard Style.

To have ESLint properly understand React JSX syntax, you need eslint-plugin-react. With this plugin, you are warned, for example, when the display name is not set for a React component, or when some dangerous JSX properties are used:

Refactoring a React application

Besides the common PhpStorm refactorings, in a React application you can also run Rename for React components: Place the cursor within the component name and press Shift+F6. Below is an example of renaming a component that is defined and used in only one file: In the same way, you can rename components defined in one file and then imported to another file using a named export:

Running and debugging a React application

Only for applications created with create-react-app.

Only for applications created with create-react-app.

The recommended way to start building a new React single page application is Create React App. Only in this case your development environment is preconfigured to use webpack and Babel. Otherwise, you need to configure a build pipeline first.

Alternatively, select a test file in the Project tool window and choose Create <file name> on the context menu.

Some known limitations

When you open an application during a debugging session for the first time, it may happen that some of the breakpoints in the code executed on page load are not hit. The reason is that to stop on a breakpoint in the original source code, PhpStorm needs to get the source maps from the browser. However the browser can pass these source maps only after the page has been fully loaded at least once. As a workaround, reload the page in the browser yourself.

If you are using webpack-dev-server from Webpack version earlier than 2, it is recommended that you disable the Safe write feature in PhpStorm. Otherwise the application won’t be updated on-time when changed. This issue is fixed in Webpack 2.