# react-lifecycle-wrap-addon

> [![NPM version](https://img.shields.io/npm/v/react-lifecycle-wrap-addon.svg?style=flat)](https://npmjs.org/package/react-lifecycle-wrap-addon) [![NPM downloads](http://img.shields.io/npm/dm/react-lifecycle-wrap-addon.svg?style=flat)](https://npmjs.org/pac

Latest version **0.0.2** (published 2016-08-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-lifecycle-wrap-addon
pnpm add react-lifecycle-wrap-addon
yarn add react-lifecycle-wrap-addon
bun add react-lifecycle-wrap-addon
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2016-08-15 |
| First published | 2016-08-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | nikogu |
| Maintainers | nikogu |
| Keywords | react-lifecycle-wrap-addon, dva, ant, react, redux, elm, frontend |

## Links

- npm: https://www.npmjs.com/package/react-lifecycle-wrap-addon
- Repository: https://github.com/nikogu/react-lifecycle-wrap-addon
- Issues: https://github.com/nikogu/react-lifecycle-wrap-addon/issues
- npm.io page: https://npm.io/package/react-lifecycle-wrap-addon

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.2 (latest) — 2016-08-15
- 0.0.1 — 2016-08-15

## README

# React Lifecycle Wrap Addon

[![NPM version](https://img.shields.io/npm/v/react-lifecycle-wrap-addon.svg?style=flat)](https://npmjs.org/package/react-lifecycle-wrap-addon)
[![NPM downloads](http://img.shields.io/npm/dm/react-lifecycle-wrap-addon.svg?style=flat)](https://npmjs.org/package/react-lifecycle-wrap-addon)

Easy to write stateless components without using Class. Enjoy functional programming.

----

#### Usage: 

```javascript

// one day, you are happliy coding ^__^
// writing stateless component, do functional programming
const Users = (props) => <div>
  <ul>
    {
      props.list.map(user=><li>{user}</li>)
    } 
  </ul>
</div>

// and then, need do something in react component's lifecycle, but pure.

// change to class
// not happy ~__~
import { Component } from React;
class Users extends Component {
  componentDidMount() {
    this.props.dispatch({
        type: 'add/user', 
    }); 
  }
  render() {
    return  <div>
        <ul>
            {
                this.props.list.map(user=><li>{user}</li>)
            } 
        </ul>
    </div>
  }
}

// or you can
// using react-lifecycle-wrap-addon, happy coding ^__^
import lifecycle from 'react-lifecycle-wrap-addon';
let Users = (props) => <div>
  <ul>
    {
      props.list.map(user=><li>{user}</li>)
    } 
  </ul>
</div>

Users = lifecycle(Users, {
  componentDidMount(props) {
    props.dispatch({
      type: 'add/user', 
    });
  }
});
```

```javascript

// you can do any lifecycle functional with react-lifecycle-wrap-addon

Users = lifecycle(Users, {
    constructor(props) {
        // ...do something 
    },
    componentDidMount(props) {
        props.dispatch({
            type: 'add/user', 
        });
    },
    componentWillReceiveProps(nextProps, props) {
        // ...do something 
    }
});

```

#### Best Practice

```javascript

// wrong
// effects side
Users = lifecycle(Users, {
  constructor(props) {
    this.state = {
      name: 'niko', 
    } 
  },
  componentDidMount(props) {
    props.dispatch({
      type: 'get/users',
      payload: this.state.name,
    })     
  },
});

// right
Users = lifecycle(Users, {
  componentDidMount(props) {
    props.dispatch({
      type: 'get/users',
      payload: props.name,
    })     
  },
});
```

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