ums2
v1.9.91
Published
FOR REACT STATE MANAGEMENT LIB
Downloads
4
Readme
ums2
FOR REACT STATE MANAGEMENT LIB
Installation
npm install ums2
Usage
import { UMS2ActionType } from "ums2"
export const actionSetStatus = (status: any) => {
return ({ type: "set-status", status } as const)
}
export type TestActions =
| UMS2ActionType<typeof actionSetStatus>
...
export function testReducer(state: ITest, action: TestActions): ITest {
switch (action.type) {
case "set-status":
return {
...state,
status: action.status
}
...
default:
return state
}
}
import { UMS2StateType, ums2Combiner } from "ums2"
export const reducers = ums2Combiner({
test: testReducer,
...
})
export type StoreState = UMS2StateType<typeof reducers>
export const initialState: StoreState = {
user: defaultTestState,
...
}
import { UMS2 } from "ums2"
Root.tsx
// ...
<UMS2 state={initialState} combine={reducers}>
<App />
</UMS2>
Example.tsx
import { useUMS2 } from "ums2";
interface Dispatch {
actionSetStatus: typeof actionSetStatus
}
const Example=()=>{
const ums2 = useUMS2<StoreState, Dispatch>({ actionSetStatus })
const show=()=>{
console.log(ums2.test.status)
}
const change=()=>{
ums2.disaptch.actionSetStatus(...)
}
return (
...
)
}