# react-component-component

> Declarative version of React.Component.

Latest version **1.2.1** (published 2018-03-04) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2018-03-04 |
| First published | 2018-02-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 17.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1058 |
| Author | Ryan Florence |
| Maintainers | ryanflorence |
| Keywords | react-component, react |

## Links

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

## 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

- 1.2.1 (latest) — 2018-03-04
- 1.2.0 — 2018-03-04
- 1.1.2 — 2018-03-03
- 1.1.1 — 2018-03-03
- 1.1.0 — 2018-03-03
- 1.0.2 — 2018-02-20
- 1.0.1 — 2018-02-17
- 1.0.0 — 2018-02-17

## README

# React Component ... Component

## What?

Declarative version of React.Component.

## Why?

Because sometimes you want a lifecycle or some state but don't want to create a new component. Also, this stuff is composable as heck.

## Installation

```bash
npm install react-component-component
# or
yarn add react-component-component
```

And then import it:

```js
// using es modules
import Component from "react-component-component";

// common.js
const Component = require("react-component-component");

// AMD
// I've forgotten but it should work.
```

Or use script tags and globals.

```html
<script src="https://unpkg.com/react-component-component"></script>
```

And then grab it off the global like so:

```js
const Component = ReactComponentComponent;
```

## How?

Let's say you want some async data but don't want to make a whole new component just for the lifecycles to get it:

```render-babel
// import Component from 'react-component-component'
const Component = ReactComponentComponent;

ReactDOM.render(
  <div>
    <h2>Let's get some gists!</h2>
    <Component
      initialState={{ gists: null }}
      didMount={({ setState }) => {
        fetch("https://api.github.com/gists")
          .then(res => res.json())
          .then(gists => setState({ gists }));
      }}
    >
      {({ state }) =>
        state.gists ? (
          <ul>
            {state.gists.map(gist => (
              <li key={gist.id}>{gist.description}</li>
            ))}
          </ul>
        ) : (
          <div>Loading...</div>
        )
      }
    </Component>
  </div>,
  DOM_NODE
);
```

Or maybe you need a little bit of state but an entire component
seems a bit heavy:

```render-babel
// import Component from 'react-component-component'
const Component = ReactComponentComponent;

ReactDOM.render(
  <Component initialState={{ count: 0 }}>
    {({ setState, state }) => (
      <div>
        <h2>Every app needs a counter!</h2>
        <button
          onClick={() =>
            setState(state => ({ count: state.count - 1 }))
          }
        >
          -
        </button>
        <span> {state.count} </span>
        <button
          onClick={() =>
            setState(state => ({ count: state.count + 1 }))
          }
        >
          +
        </button>
      </div>
    )}
  </Component>,
  DOM_NODE
);
```

## Props

You know all of these already:

* `didMount({ state, setState, props, forceUpdate })`
* `shouldUpdate({ state, props, nextProps, nextState })`
* `didUpdate({ state, setState, props, forceUpdate, prevProps, prevState })`
* `willUnmount({ state, props })`
* `children({ state, setState, props, forceUpdate })`
* `render({ state, setState, props, forceUpdate })`

## Legal

Released under MIT license.

Copyright &copy; 2017-present Ryan Florence

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