質問編集履歴

2

storeの追記

2020/10/29 13:27

投稿

nanase21
nanase21

スコア144

test CHANGED
File without changes
test CHANGED
@@ -157,3 +157,33 @@
157
157
 
158
158
 
159
159
  ```
160
+
161
+
162
+
163
+ ```ts
164
+
165
+ import { createStore, applyMiddleware, compose } from 'redux';
166
+
167
+ import thunk from "redux-thunk"
168
+
169
+ import rootReducer from './reducers/root_reducers';
170
+
171
+
172
+
173
+ const storeEnhancers = (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
174
+
175
+
176
+
177
+ const store = createStore(
178
+
179
+ rootReducer,
180
+
181
+ storeEnhancers(applyMiddleware(thunk))
182
+
183
+ );
184
+
185
+
186
+
187
+ export default store
188
+
189
+ ```

1

コードの追記

2020/10/29 13:26

投稿

nanase21
nanase21

スコア144

test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
 
8
8
 
9
- ```js
9
+ ```ts
10
10
 
11
11
  import { SING_IN, SING_OUT } from './types';
12
12
 
@@ -61,3 +61,99 @@
61
61
  ``action.payload``にはちゃんと値は入ってきているのでstateを更新方法を知りたいです。
62
62
 
63
63
  更新したい``case``は``SIGN_IN``で、``SIGN_IN``の中に処理は入ってきています。
64
+
65
+
66
+
67
+
68
+
69
+ ### 追記
70
+
71
+
72
+
73
+ ```ts
74
+
75
+ // actionです
76
+
77
+ export const signInAction = (userState: any) => {
78
+
79
+ return {
80
+
81
+ type: SING_IN,
82
+
83
+ payload: {
84
+
85
+ user: {
86
+
87
+ userId: userState.userId,
88
+
89
+ firstName: userState.firstName,
90
+
91
+ lastName: userState.lastName
92
+
93
+ }
94
+
95
+ }
96
+
97
+ }
98
+
99
+ };
100
+
101
+ ```
102
+
103
+
104
+
105
+ ```ts
106
+
107
+ // initial_stateです
108
+
109
+ export interface State {
110
+
111
+ user: {
112
+
113
+ userId: string
114
+
115
+ firstName: string
116
+
117
+ lastName: string
118
+
119
+ }
120
+
121
+ }
122
+
123
+
124
+
125
+ export const initialState: State = {
126
+
127
+ user: {
128
+
129
+ userId: "",
130
+
131
+ firstName: "",
132
+
133
+ lastName: ""
134
+
135
+ }
136
+
137
+ }
138
+
139
+ ```
140
+
141
+
142
+
143
+ ```ts
144
+
145
+ const dispatch = useDispatch();
146
+
147
+ // container
148
+
149
+ <div className="form-control">
150
+
151
+ <input type="submit" onClick={() => dispatch(signInAction(
152
+
153
+ { userId: 'xxx', firstName: 'test', lastName: 'user' }))} />
154
+
155
+ </div>
156
+
157
+
158
+
159
+ ```