1.0.9 • Published 5 years ago

react-soliit v1.0.9

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

react-soliit :balloon:

Simple state management solution for React

The 'Store' is all you need

No contexts, or redux, or providers, or consumers, or subscribers, or reducers, or actions, or sagas, or thunks, or epics. None of that. Simply

  1. Create store(s)
  2. Connect to store(s)

That's it

Installation

npm install react-soliit --save

Example

Imports

import React from "react";
import { render } from "react-dom";
import StateStore, { withStores } from "react-soliit";

Create the Store

const counterStore = new StateStore({ count: 0 });

Create component

const Counter = function({ counterStore }) {
  const increment = () =>
    counterStore.setState({ count: counterStore.state.count + 1 });
  const decrement = () =>
    counterStore.setState({ count: counterStore.state.count - 1 });
  return (
    <div>
      <button onClick={decrement}>-</button>
      <span>{counterStore.state.count}</span>
      <button onClick={increment}>+</button>
    </div>
  );
};

Connect component with the Store

const ConnectedCounter = withStores(Counter, { counterStore });

Render to DOM

render(<ConnectedCounter />, document.getElementById("root"));

using withStores HOC

The withStores HOC maps store instances to component props. This allows for the injection of mock stores during testing.

Live Examples

Counter Example

Async Action Example

That's all folks

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago