質問編集履歴

1

ファイルのパスとソースの追加

2020/10/26 01:21

投稿

nanase21
nanase21

スコア144

test CHANGED
File without changes
test CHANGED
@@ -37,3 +37,155 @@
37
37
  });
38
38
 
39
39
  ```
40
+
41
+
42
+
43
+ **追記**
44
+
45
+
46
+
47
+ ```js
48
+
49
+ // src/reducers/postReducer.js
50
+
51
+
52
+
53
+ import { FETCH_POSTS, NEW_POST, SING_IN, SING_OUT } from '../types';
54
+
55
+ import initialState from './initialState';
56
+
57
+
58
+
59
+ export default function posts(state = initialState, action) {
60
+
61
+ switch (action.type) {
62
+
63
+ case FETCH_POSTS:
64
+
65
+ return {
66
+
67
+ ...state,
68
+
69
+ items: action.payload
70
+
71
+ };
72
+
73
+ case NEW_POST:
74
+
75
+ return {
76
+
77
+ ...state,
78
+
79
+ item: action.payload
80
+
81
+ };
82
+
83
+ default:
84
+
85
+ return state;
86
+
87
+ }
88
+
89
+ }
90
+
91
+ ```
92
+
93
+
94
+
95
+ ```js
96
+
97
+ // src/reducers/userReducer.js
98
+
99
+ import { FETCH_POSTS, NEW_POST, SING_IN, SING_OUT } from '../types';
100
+
101
+ import initialState from './initialState';
102
+
103
+
104
+
105
+ export default function user(state = initialState, action) {
106
+
107
+ switch (action.type) {
108
+
109
+ case SING_IN:
110
+
111
+ return {
112
+
113
+ ...state,
114
+
115
+ ...action.payload
116
+
117
+ };
118
+
119
+ case SING_OUT:
120
+
121
+ return {
122
+
123
+ ...state,
124
+
125
+ ...action.payload
126
+
127
+ };
128
+
129
+ default:
130
+
131
+ return state;
132
+
133
+ }
134
+
135
+ }
136
+
137
+ ```
138
+
139
+
140
+
141
+ ```js
142
+
143
+ // src/reducers/initialState.js
144
+
145
+
146
+
147
+ const initialState = {
148
+
149
+ items: [],
150
+
151
+ item: {},
152
+
153
+ user: {
154
+
155
+ isSignedIn: false,
156
+
157
+ firstName: "",
158
+
159
+ lastName: "",
160
+
161
+ userId: "",
162
+
163
+ address: {
164
+
165
+ zipCode: "",
166
+
167
+ stateName: "",
168
+
169
+ city: "",
170
+
171
+ line: "",
172
+
173
+ line2: "",
174
+
175
+ buidingName: ""
176
+
177
+ }
178
+
179
+ }
180
+
181
+ };
182
+
183
+
184
+
185
+ export default initialState
186
+
187
+ ```
188
+
189
+
190
+
191
+ 肝心なファイルの詳細がないという指摘を受けたので、reducerのソースコードとファイルパスを追記させて頂きました。