@e7w/easy-model
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

easy-model

一个简单的react状态管理库

示例

import { useModel } from "@e7w/easy-model";

class MTest {
  constructor(public name: string) {}

  value = 0;

  random() {
    this.value = Math.random();
  }
}

function TestComA() {
  const { value, random } = useModel(MTest, ["test"]);
  return (
    <div>
      <span>{value}</span>
      <button onClick={random}>changeValue</button>
    </div>
  );
}

function TestComB() {
  const { value } = useModel(MTest, ["test"]);
  return <span>{value}</span>;
}

render(
  <div>
    <TestComA />
    <TestComB />
  </div>
);
// 当点击ComA的div时,两个组件都会更新

Readme

Keywords

none

Package Sidebar

Install

npm i @e7w/easy-model

Weekly Downloads

76

Version

0.1.1

License

MIT

Unpacked Size

12.1 kB

Total Files

6

Last publish

Collaborators

  • q344275632