Redux
Subtitle
Container
1. Store Implementation
Something about redux store
0
1
2
3
4
5
6
7
8
9
10
11
12
13
// Configure the store.
const store = configureStore({
reducer: {
TestDataType: testDataTypeSlice,
}
});
// Export the types
export type RootState = ReturnType<typeof store.getState>; // Export the type of the state
export type AppDispatch = typeof store.dispatch; // Export the type of the dispatch
// Export the store
export default store;
2. Slice Implementation
Something about redux slices
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Create slice for a type of data.
const testDataTypeSlice = createSlice({
name: 'TestDataType',
initialState: {name: "", lastName: "" } as TestDataType,
reducers: {
resetName: (state: TestDataType) => {
state.lastName = "";
state.name = "";
},
changeName: (state: TestDataType, action) => {
state.name = action.payload;
},
changeLastName: (state: TestDataType, action) => {
state.lastName = action.payload;
},
update: (state: TestDataType, action) => {
state.name = action.payload.name;
state.lastName = action.payload.lastName;
}
}
});
// Export the actions and the reducer
export const { resetName, changeName, changeLastName, update} = testDataTypeSlice.actions;
export default testDataTypeSlice.reducer;