Skip to content
master
Switch branches/tags
Code

Latest commit

* chore: peerDep react version compatible 17.x

commit c11cef5
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Wed Jun 16 21:06:01 2021 +0800

    chore: version

commit 5444efc
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Wed Jun 16 21:03:15 2021 +0800

    chore: add dingding notify

commit df44514
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Wed Jun 16 21:00:37 2021 +0800

    chore: add dingding notify

commit 43bb31e
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Wed Jun 16 20:56:15 2021 +0800

    chore: add dingding notify

commit 9893cdf
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Wed Jun 16 20:28:14 2021 +0800

    chore: add publish

commit d4ce841
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Wed Jun 16 20:26:18 2021 +0800

    chore: add publish

commit de1ee63
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Wed Jun 16 20:17:38 2021 +0800

    chore: add publish

commit 0d6daab
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Wed Jun 16 17:48:04 2021 +0800

    chore: add publish

commit 5f117f0
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Wed Jun 16 17:43:10 2021 +0800

    chore: add publish

commit 6c03a98
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Wed Jun 16 17:30:28 2021 +0800

    chore: add publish

commit ed328f7
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Wed Jun 16 17:27:52 2021 +0800

    chore: add publish

commit 4dcc1ae
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Wed Jun 16 17:20:40 2021 +0800

    chore: add publish

commit 2e2d452
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Wed Jun 16 17:18:09 2021 +0800

    chore: add publish

commit 14951c9
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Wed Jun 16 17:15:28 2021 +0800

    chore: add publish

commit 222681b
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Wed Jun 16 17:12:46 2021 +0800

    chore: add publish

commit ca8c36c
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Wed Jun 16 15:50:19 2021 +0800

    chore: react-scripts -> icejs

commit 62d81ae
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Wed Jun 16 15:20:29 2021 +0800

    chore: ts error

commit 31fa1b7
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Tue Jun 15 18:07:12 2021 +0800

    chore: upgrade ts to 4

commit 6391127
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Tue Jun 15 17:28:38 2021 +0800

    chore: fix ci

commit 808922e
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Tue Jun 15 17:21:15 2021 +0800

    chore: node_modules cache

commit db1dbcb
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Tue Jun 15 17:19:00 2021 +0800

    chore: node_modules cache

commit 1140ccc
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Tue Jun 15 17:17:31 2021 +0800

    chore: node_modules cache

commit 7fd326a
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Tue Jun 15 16:56:30 2021 +0800

    chore: add lock file to git

commit 2518dbf
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Tue Jun 15 16:48:05 2021 +0800

    chore: travis -> github actions

commit cca281f
Author: liuxiong.lx <liuxiong.lx@alibaba-inc.com>
Date:   Tue Jun 15 15:51:24 2021 +0800

    chore: peerDep react version compatible 17.x

* chore: link

* chore: version

* chore: use prettier replace editorconfig

* chore: bump version
de76ab8

Git stats

Files

Permalink
Failed to load latest commit information.

English | 简体中文

icestore

Simple and friendly state for React.

NPM version Package Quality build status NPM downloads Known Vulnerabilities David deps codecov

🕹 CodeSandbox demos 🕹
Counter Todos

Introduction

icestore is a simple and friendly state management library for React. It has the following core features:

  • Minimal & Familiar API: No additional learning costs, easy to get started with the knowledge of Redux && React Hooks.
  • Built in Async Status: Records loading and error status of effects, simplifying the rendering logic in the view layer.
  • Class Component Support: Make old projects enjoying the fun of lightweight state management with friendly compatibility strategy.
  • TypeScript Support: Provide complete type definitions to support intelliSense in VS Code.

See the comparison table for more details.

Basic example

import React from 'react';
import ReactDOM from 'react-dom';
import { createStore } from '@ice/store';

const delay = (time) =>
  new Promise((resolve) => setTimeout(() => resolve(), time));

// 1️⃣ Use a model to define your store
const counter = {
  state: 0,
  reducers: {
    increment: (prevState) => prevState + 1,
    decrement: (prevState) => prevState - 1,
  },
  effects: () => ({
    async asyncDecrement() {
      await delay(1000);
      this.decrement();
    },
  }),
};

const models = {
  counter,
};

// 2️⃣ Create the store
const store = createStore(models);

// 3️⃣ Consume model
const { useModel } = store;
function Counter() {
  const [count, dispatchers] = useModel('counter');
  const { increment, asyncDecrement } = dispatchers;
  return (
    <div>
      <span>{count}</span>
      <button type="button" onClick={increment}>
        +
      </button>
      <button type="button" onClick={asyncDecrement}>
        -
      </button>
    </div>
  );
}

// 4️⃣ Wrap your components with Provider
const { Provider } = store;
function App() {
  return (
    <Provider>
      <Counter />
    </Provider>
  );
}

const rootElement = document.getElementById('root');
ReactDOM.render(<App />, rootElement);

Installation

icestore requires React 16.8.0 or later.

npm install @ice/store --save

Documents

Examples

Browser Compatibility

Chrome Firefox Edge IE Safari Opera UC
✔ ✔ ✔ 9+ ✔ ✔ ✔ ✔

Inspiration

icestore refines and builds upon the ideas of rematch & constate.

Contributors

Feel free to report any questions as an issue, we'd love to have your helping hand on icestore.

If you're interested in icestore, see CONTRIBUTING.md for more information to learn how to get started.

Develop:

$ cd icestore/
$ npm install
$ npm run watch

$ cd examples/counter
$ npm install
$ npm link ../../                    # link icestore
$ npm link ../../node_modules/react  # link react
$ npm start

License

MIT