Wegar 前端状态管理
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)
}
// types/stores.d.ts
export * from 'wegar-store'
declare module 'wegar-store' {
export interface WegarStores {
'count': number
}
}