@nait-aits/redux
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Installation

// with npm
npm install @nait-aits/redux

Update Notes

  • May 16, 2022 - React 18. May work with older versions of react. YMMV.

Usage Example (duck file)

import { createAsyncAction, ReducerState } from "@nait-aits/redux";

const controlName = "samplePage";

type LoadTestData = {
    data: string;
};

var loadTest = createAsyncAction<LoadTestData, { id: string | number }, State>({
  actionPrefix: controlName,
  actionName: "loadTestData",
  url:"https://someUrl",
  pending: (state, action) => {
    state.testDataState.isLoading = true;
    state.testDataState.data = undefined;
  },
  fulfilled: (state, action) => {
    state.testDataState.isLoading = false;
    state.testDataState.data = action.payload;
  },
  rejected: (state, action) => {
    state.testDataState.isLoading = false;
    state.testDataState.error = action.payload;
  },
});

type State = {
  testDataState: ReducerState<LoadTestData>;
};

var slice = createSlice({
  name: controlName,
  initialState: {
    testDataState: {
      isLoading: false,
    },
  } as State,
  reducers: {},
  extraReducers: {
    ...loadTest.reducer,
  },
});

const ret = {
  reducer: {
    [controlName]: slice.reducer,
  },
  actions: {
    [controlName]: {
      ...slice.actions,
      loadTest: loadTest.action,
    },
  },
};

Readme

Keywords

none

Package Sidebar

Install

npm i @nait-aits/redux

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

328 kB

Total Files

24

Last publish

Collaborators

  • kenlinait
  • edelyn