ums2

1.9.91 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i ums2

Weekly Downloads

2

Version

1.9.91

License

MIT

Unpacked Size

6.14 kB

Total Files

7

Last publish

Collaborators

  • ademirtemur