react-unstated
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

React-unstated

Redux-like connect for unstated.

Installation

npm install --save react-unstated

Usage

import React from 'react';
import ReactDOM from 'react-dom';
import { Container, Provider } from 'unstated';
import { connect } from 'react-unstated';

class CounterContainer extends Container {
  state = {
    count: 0
  }

  increase = () => {
    this.setState({
      count: this.state.count + 1
    });
  }
}

const Counter = ({ n, inc }) => (
  <div>
    <div>{n}</div>
    <div>
      <button onClick={inc}>Increase</button>
    </div>
  </div>
);

const EnchancedCounter = connect(Counter, CounterContainer, (c) => {
  return {
    n: c.state.count,
    inc: c.increase
  };
});

ReactDOM.render((
  <Provider>
    <EnchancedCounter />
  </Provider>
), document.getElementById('root'));

Package Sidebar

Install

npm i react-unstated

Weekly Downloads

2

Version

0.0.3

License

MIT

Unpacked Size

6.24 kB

Total Files

9

Last publish

Collaborators

  • sdman