Skip to content

Latest commit

 

History

History
78 lines (51 loc) · 2.11 KB

README-zh_CN.md

File metadata and controls

78 lines (51 loc) · 2.11 KB

region-core

version npm downloads codecov MIT License

region-core 是一个 React 渐进式状态管理框架,你可以在使用 react state,redux 的同时使用它,并获得开发的便利。

English | 中文

Get Started

  • 安装
npm i region-core
  • 在 region 的基础上构造一个组件
import {createRegion} from 'region-core';

const region = createRegion<string>('initialValue');

const handleChange = e => region.set(e.target.value);

const Component = () => {
    const value = region.useValue();
    return <input value={value} onChange={handleChange} />;
};
  • 使用 region 请求数据
import {createRegion} from 'region-core';

const region = createRegion<User>();

const loadUser = region.loadBy(asyncFuncion);

// call loadUser in application lifecycle
loadUser({userId: 1});

const Component = () => {
    const value = region.useValue();
    const loading = region.useLoading();
    const error = region.useError();

    // ...
    return <div>{value}</div>;
}

文档

中文文档和最佳实践

迁移指南

更新日志

征求意见(rfcs)

示例

在线示例

git clone https://github.com/regionjs/region-core.git
cd example
npm i
npm start

服务端渲染: NextJs with Region