regionjs / region-core

Progressive View Model Management Library

Home Page:https://regionjs.github.io/region-core

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

region-core

version npm downloads codecov MIT License

region-core is a progressive View Model Management Framework. You can use it while using react state, redux, and benefit from it.

English | 中文

Get Started

  • install
npm i region-core
  • Build your Component above 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} />;
};
  • Fetching data with 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>;
}

Docs

Document And Best Practices

Migrate Guide

ChangeLog

Request for Comments

Example

Online Example

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

SSR: NextJs with Region

Contribute

Feel free to raise issues and PR.

About

Progressive View Model Management Library

https://regionjs.github.io/region-core

License:MIT License


Languages

Language:TypeScript 98.4%Language:JavaScript 0.8%Language:HTML 0.4%Language:CSS 0.4%Language:Shell 0.1%