react-state2000

0.0.3 • Public • Published

react-state2000

Simple state for React

Inspired by Elm and Hyperapp, a super simple state handler for React.

Usage

Installation

npm install react-state2000 --save

Create a store

In store.js:

import { connect } from "react-state2000";

const state = {
  count: { value: 0 }
};

const actions = {
  count: {
    add: n => (state, actions) => ({
      value: state.value + n
    }),
    sub: n => (state, actions) => ({
      value: state.value - n
    })
  }
};

const withState = connect(
  state,
  wiredActions
);

export { withState };

In App component

import React from "react";

const AppComponent = ({ state, actions }) => (
  <div className="App">
    <p>Value is:</p>
    <h1>{state.count.value}</h1>
    <button onClick={() => actions.count.add(1)}>+</button>
    <button onClick={() => actions.count.sub(1)}>-</button>
  </div>
);

export default AppComponent;

In index

import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import { withState } from "./store";

const AppWithState = withState(App);
ReactDOM.render(<AppWithState />, document.getElementById("root"));

Package Sidebar

Install

npm i react-state2000

Weekly Downloads

1

Version

0.0.3

License

MIT

Unpacked Size

91.1 kB

Total Files

4

Last publish

Collaborators

  • judas-christ