JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 23
  • Score
    100M100P100Q49432F
  • License MIT

region-react

Package Exports

  • region-react
  • region-react/es/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (region-react) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

region-react

react-react along with region-vanilla provide a way to manage global context. Supports React, NextJS, Node, Vanilla. You can use it while using any current solution. (Such as useStatecreateContextreduxrecoilmobxjotai)

English | 中文

Get Started

  • install
npm i region-react
  • Build your Component above region
import {createRegion} from 'region-react';

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-react';

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

See region README for more information.