# babel-plugin-optimize-react

> Babel plugin for optimizing common React patterns

Latest version **0.0.4** (published 2019-01-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-optimize-react
pnpm add babel-plugin-optimize-react
yarn add babel-plugin-optimize-react
bun add babel-plugin-optimize-react
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities; popular repo; extremely popular.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2019-01-21 |
| First published | 2019-01-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 103231 |
| Maintainers | acdlite, brianvaughn, fb, gaearon, sebmarkbage, threepointone, trueadm |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-optimize-react
- Repository: https://github.com/facebookincubator/create-react-app
- Homepage: https://github.com/facebookincubator/create-react-app#readme
- Issues: https://github.com/facebookincubator/create-react-app/issues
- npm.io page: https://npm.io/package/babel-plugin-optimize-react

## Recent versions

- 0.0.4 (latest) — 2019-01-21
- 0.0.3 — 2019-01-17
- 0.0.2 — 2019-01-17
- 0.0.1 — 2019-01-17

## README

# babel-plugin-optimize-react

This Babel 7 plugin optimizes React hooks by transforming common patterns into more effecient output when using with tools such as [Create React App](https://github.com/facebook/create-react-app). For example, with this plugin the following output is optimized as shown:

```js
// Original
var _useState = Object(react__WEBPACK_IMPORTED_MODULE_1_["useState"])(Math.random()),
    _State2 = Object(_Users_gaearon_p_create_rreact_app_node_modules_babel_runtime_helpers_esm_sliceToArray_WEBPACK_IMPORTED_MODULE_0__["default"])(_useState, 1),
    value = _useState2[0];
    
// With this plugin
var useState = react__WEBPACK_IMPORTED_MODULE_1_.useState;
var __ref__0 = useState(Math.random());
var value = __ref__0[0];
```

## Named imports to hooks get transformed

```js
// Original
import React, {useState} from 'react';

// With this plugin
import React from 'react';
const {useState} = React;
```

## Array destructuring transform for React's built-in hooks

```js
// Original
const [counter, setCounter] = useState(0);

// With this plugin
const __ref__0 = useState(0);
const counter = __ref__0[0];
const setCounter = __ref__0[1];
```

## React.createElement becomes a hoisted constant

```js
// Original
import React from 'react';

function MyComponent() {
  return React.createElement('div', null, 'Hello world');
}

// With this plugin
import React from 'react';
const __reactCreateElement__ = React.createElement;

function MyComponent() {
  return __reactCreateElement__('div', null, 'Hello world');
}
```

---
_Source: https://npm.io/package/babel-plugin-optimize-react · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
