1.9.91 • Published 8 months ago

ums2 v1.9.91

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

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 (
        ...
    )
}
1.9.91

8 months ago

1.9.71

9 months ago

1.9.67

9 months ago

1.9.55

9 months ago

1.9.11

9 months ago

1.9.9

9 months ago