# add-react

> Add react allows you to create react stateless & class components from the CLI, updated with 16.6.0 lifecycle methods

Latest version **2.0.0** (published 2018-10-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install add-react
pnpm add add-react
yarn add add-react
bun add add-react
```

Provides the command `add-react`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2018-10-24 |
| First published | 2017-11-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 843.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | dj10dj100 |
| Maintainers | dj10dj100 |
| Keywords | add, react, create, component, cli, command, line, interface, node, tool |

## Links

- npm: https://www.npmjs.com/package/add-react
- Repository: https://github.com/dj10dj100/add-react
- Homepage: https://github.com/dj10dj100/add-react#readme
- Issues: https://github.com/dj10dj100/add-react/issues
- npm.io page: https://npm.io/package/add-react

## Dependencies (4)

- [global](https://npm.io/package/global.md) ^4.3.2
- [inquirer](https://npm.io/package/inquirer.md) ^3.3.0
- [add-react](https://npm.io/package/add-react.md) ^1.0.1
- [commander](https://npm.io/package/commander.md) ^2.11.0

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2018-10-24
- 1.0.13 — 2017-11-22
- 1.0.12 — 2017-11-22
- 1.0.11 — 2017-11-22
- 1.0.10 — 2017-11-11
- 1.0.9 — 2017-11-11
- 1.0.7 — 2017-11-06
- 1.0.6 — 2017-11-05
- 1.0.5 — 2017-11-04
- 1.0.4 — 2017-11-04
- 1.0.3 — 2017-11-04
- 1.0.2 — 2017-11-04
- 1.0.1 — 2017-11-04
- 1.0.0 — 2017-11-04
- 0.0.2 — 2017-11-04
- … 1 more at https://npm.io/package/add-react/versions

## README

[![npm](https://img.shields.io/npm/dm/add-react.svg)]()
[![npm](https://img.shields.io/npm/dt/add-react.svg)]()
[![npm](https://img.shields.io/npm/v/add-react.svg)]()

![](how-to.gif)

Updated to contain lifecycle methods from react 16.6.0+

**Note** This means UNSAFE methods are added by default.

# Add React components from cli

- Supports JSX flavoured components
- Can make class (stateful) or stateless component
- Uses UMD (universal module syntax) for wider support

  Commands:

### Installation

Add as a global

```javascript
yarn add add-react -g
```

or

```javascript
npm install add-react -g
```

or to add to current project only

```javascript
yarn add add-react
```

To use:

```javascript
add-react <command>
```

### Commands

```javascript
component | c;
```

Adds a new react component, this will walk you through a few steps to create the component
example:

```javascript
add-react component
```

or

```javascript
add-react c
```

### Options:

add-react supports two component types

#### Stateless (functional)

Stateless functional component only has 2 configuration options:

- Component name
- Filename

#### ES6 Class

Es6 class contain boilerplate code for stateful component extending react.component.
Has 3 options:

- Component name
- Filename
- LifecycleMethods - if 'true' boilerplate contains all default react components.

---

### Example Component:

```javascript
const React = require("react");

class Navigation extends React.Component {
  constructor(props) {
    super(props);
    this.state = {};
  }
  static getDerivedStateFromProps(props, state) {
    return {};
  }

  UNSAFE_componentWillMount() {}

  componentDidMount() {}

  UNSAFE_componentWillReceiveProps() {}

  shouldComponentUpdate() {}

  UNSAFE_componentWillUpdate() {}

  componentDidUpdate() {}

  componentWillUnmount() {}

  render() {
    return <div />;
  }
}

module.exports = Navigation;
```

### CLI only

If you prefer to just use a one liner and not go through the questions you can use the following:

```javascript
add-react cli <componentType> <componentName> <filename> [lifecycle]
```

```
componentType
```

_Class_ or _Stateless_

```javascript
componentName;
```

Component Name

```javascript
filename;
```

filename - e.g Component.jsx

```javascript
lifecycle;
```

_boolean_ - whether class (stateful) component should contain all lifecycle methods

#### Options

-V, --version output the version number

-h, --help output usage information

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