-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoolkit.js
More file actions
36 lines (27 loc) · 865 Bytes
/
toolkit.js
File metadata and controls
36 lines (27 loc) · 865 Bytes
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
26
27
28
29
30
31
32
33
34
35
36
import * as toolkitRaw from "@reduxjs/toolkit";
const { configureStore, createAction, createReducer } = toolkitRaw;
const addToCart = createAction("ADD_TO_CART");
const cartReducer = createReducer([], (builder) => {
builder.addCase(addToCart, (state, action) => {
state.push(action.payload);
});
});
const login = createAction("CREATE_SESSION");
const loginReducer = createReducer({ status: false }, (builder) => {
builder.addCase(login, (state, action) => {
state.status = true;
});
});
const store = configureStore({
reducer: {
login: loginReducer,
cart: cartReducer,
},
});
console.log("oncreate store : ", store.getState());
store.subscribe(() => {
console.log("STORE CHANGE : ", store.getState());
});
store.dispatch(addToCart({ id: 1, qty: 20 }));
store.dispatch(addToCart({ id: 2, qty: 10 }));
store.dispatch(login());