Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

基于 react hooks 实现的极简全局状态管理库 #53

Closed
masx200 opened this issue Jul 5, 2019 · 0 comments
Closed

基于 react hooks 实现的极简全局状态管理库 #53

masx200 opened this issue Jul 5, 2019 · 0 comments

Comments

@masx200
Copy link

masx200 commented Jul 5, 2019

  • 项目名称:
    基于 react hooks 实现的极简全局状态管理库

  • 项目地址:
    https://github.com/masx200/react-simple-global-state-store-hook

  • 类别:
    javascript

  • 项目简介 (100 字以内):

  • 项目描述:
    基于 react hooks 实现的极简全局状态管理库,可以跨组件共享全局状态
    仅仅使用 44 行代码写成的极简 react 全局状态管理库!

  • 推荐理由:
    跟 redux 对比,极为简洁!抛弃 redux!
    redux主要由store,action,reducer等等组成,过于庞大负杂,繁琐

react-simple-global-state-store-hook只管理状态仓库,修改全局状态的方法返回给组件内部调用,就跟使用useState一样简单!

  • 示例代码:
import useGlobalstate from "react-simple-global-state-store-hook";
function Htest() {
  const {
    number: [number, setnumber]
  } = useGlobalstate({ number: 78546 });

  //全局状态 number 生成 ,初始值为 78546

  return (
    <div>
      <p>
        number:
        {number}
      </p>
      <button
        onClick={() => {
          setnumber(number * 3);
          /*修改全局状态number,其他使用了全局状态number的组件也会刷新数据*/
        }}
      >
        修改number
      </button>
    </div>
  );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants