Skip to content

qnnp-me/wegar-store

Repository files navigation

Wegar Store

Wegar 前端状态管理

在 React 中

import {useStore} from 'wegar-store'

export const App = () => {
  const [count, setCount] = useStore('count', 0)
  return (
    <>
      <div>count: {count}</div>
      <button onClick={() => setCount(count + 1)}>+1</button>
    </>
  )
}

其他项目中

import {getStore} from 'wegar-store'

const {getState, subscribe} = getStore('count', 0)

subscribe(store => {
  console.log('new state:', store.state)
})

const updateState = () => {
  getState().setState(getState().state + 1)
}

定义 Store 类型

// types/stores.d.ts
export * from 'wegar-store'
declare module 'wegar-store' {
  export interface WegarStores {
    'count': number
  }
}

About

Wegar 前端状态管理

Resources

Stars

Watchers

Forks

Packages

No packages published