質問編集履歴
1
ファイルのパスとソースの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -17,4 +17,80 @@
|
|
17
17
|
export default combineReducers({
|
18
18
|
user: userReducer
|
19
19
|
});
|
20
|
-
```
|
20
|
+
```
|
21
|
+
|
22
|
+
**追記**
|
23
|
+
|
24
|
+
```js
|
25
|
+
// src/reducers/postReducer.js
|
26
|
+
|
27
|
+
import { FETCH_POSTS, NEW_POST, SING_IN, SING_OUT } from '../types';
|
28
|
+
import initialState from './initialState';
|
29
|
+
|
30
|
+
export default function posts(state = initialState, action) {
|
31
|
+
switch (action.type) {
|
32
|
+
case FETCH_POSTS:
|
33
|
+
return {
|
34
|
+
...state,
|
35
|
+
items: action.payload
|
36
|
+
};
|
37
|
+
case NEW_POST:
|
38
|
+
return {
|
39
|
+
...state,
|
40
|
+
item: action.payload
|
41
|
+
};
|
42
|
+
default:
|
43
|
+
return state;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
```
|
47
|
+
|
48
|
+
```js
|
49
|
+
// src/reducers/userReducer.js
|
50
|
+
import { FETCH_POSTS, NEW_POST, SING_IN, SING_OUT } from '../types';
|
51
|
+
import initialState from './initialState';
|
52
|
+
|
53
|
+
export default function user(state = initialState, action) {
|
54
|
+
switch (action.type) {
|
55
|
+
case SING_IN:
|
56
|
+
return {
|
57
|
+
...state,
|
58
|
+
...action.payload
|
59
|
+
};
|
60
|
+
case SING_OUT:
|
61
|
+
return {
|
62
|
+
...state,
|
63
|
+
...action.payload
|
64
|
+
};
|
65
|
+
default:
|
66
|
+
return state;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
```
|
70
|
+
|
71
|
+
```js
|
72
|
+
// src/reducers/initialState.js
|
73
|
+
|
74
|
+
const initialState = {
|
75
|
+
items: [],
|
76
|
+
item: {},
|
77
|
+
user: {
|
78
|
+
isSignedIn: false,
|
79
|
+
firstName: "",
|
80
|
+
lastName: "",
|
81
|
+
userId: "",
|
82
|
+
address: {
|
83
|
+
zipCode: "",
|
84
|
+
stateName: "",
|
85
|
+
city: "",
|
86
|
+
line: "",
|
87
|
+
line2: "",
|
88
|
+
buidingName: ""
|
89
|
+
}
|
90
|
+
}
|
91
|
+
};
|
92
|
+
|
93
|
+
export default initialState
|
94
|
+
```
|
95
|
+
|
96
|
+
肝心なファイルの詳細がないという指摘を受けたので、reducerのソースコードとファイルパスを追記させて頂きました。
|