@nait-aits/redux
v1.0.0
Published
```console // with npm npm install @nait-aits/redux ```
Downloads
22
Readme
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,
},
},
};