V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
爱意满满的作品展示区。
yzhen123

nstate: 一个轻量级+低心智负担的 React 状态管理库

  •  
  •   yzhen123 · Oct 18, 2021 · 2422 views
    This topic created in 1659 days ago, the information mentioned may be changed or developed.

    特性:

    1. 极简 API + 良好的 TS 支持
    2. 内置 immer 简化深层状态更新
    3. 自动绑定 action 方法
    4. 支持多 store 相互组合复用
    5. 支持监听状态变化

    Counter demo:

    repo: https://github.com/zaaack/nstate

    6 replies    2021-10-19 11:16:37 +08:00
    Lanayaaa
        1
    Lanayaaa  
       Oct 18, 2021
    有类似 vue 的 computed 值吗?
    yzhen123
        2
    yzhen123  
    OP
       Oct 18, 2021
    @PainAndLove 没有,但是有 .useState 可以实现类似功能
    cyberpoint
        3
    cyberpoint  
       Oct 18, 2021
    redux-toolkit 挺好用的
    Lanayaaa
        4
    Lanayaaa  
       Oct 19, 2021
    @yzhen123 还是不太方便。 如果在多个组件里用,每个组件里都得重复写。
    yzhen123
        5
    yzhen123  
    OP
       Oct 19, 2021
    @PainAndLove 可以封装成 Store 上的方法,

    ```ts
    class Store extends NState {
    useCount() {

    }
    }
    ```
    yzhen123
        6
    yzhen123  
    OP
       Oct 19, 2021
    @PainAndLove 可以封装成 Store 上的方法,

    ```ts
    class Store extends NState {
    useCount() {
    return this.useState(s => s.count + 1)
    }
    }
    ```
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2691 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 53ms · UTC 13:11 · PVG 21:11 · LAX 06:11 · JFK 09:11
    ♥ Do have faith in what you're doing.