質問編集履歴

2

別エラーが発生したため加筆しました(_ _)

2018/02/11 12:58

投稿

yamady
yamady

スコア176

test CHANGED
File without changes
test CHANGED
@@ -399,3 +399,187 @@
399
399
  };
400
400
 
401
401
  ```
402
+
403
+
404
+
405
+ ## 追記②
406
+
407
+ ご指摘いただいたようにすると、どうやらredux部分は解決したように思えるのですが(ありがとうございます!)根本的なエラーはこちらであったようなきがします。
408
+
409
+
410
+
411
+ ```JavaScript
412
+
413
+ Actions must be plain objects. Use custom middleware for async actions.
414
+
415
+ ```
416
+
417
+
418
+
419
+ もしかしたら、自分の書き方がひどすぎるのかもしれません(涙
420
+
421
+
422
+
423
+ エラーの続き
424
+
425
+ ```
426
+
427
+ This error is located at:
428
+
429
+ in Home (created by Connect(Home))
430
+
431
+ in Connect(Home) (at SceneView.js:31)
432
+
433
+ in SceneView (at CardStack.js:405)
434
+
435
+ in RCTView (at View.js:71)
436
+
437
+ in View (at createAnimatedComponent.js:147)
438
+
439
+ in AnimatedComponent (at Card.js:26)
440
+
441
+ in Card (at PointerEventsContainer.js:55)
442
+
443
+ in Container (at CardStack.js:436)
444
+
445
+ in RCTView (at View.js:71)
446
+
447
+ ・・・
448
+
449
+ ```
450
+
451
+
452
+
453
+ ### ソースコード
454
+
455
+
456
+
457
+ > Home.js
458
+
459
+
460
+
461
+ ```
462
+
463
+ import _ from 'lodash';
464
+
465
+ import React from 'react';
466
+
467
+ import { connect } from 'react-redux';
468
+
469
+ import { ListView, Image, Text, View, StyleSheet } from 'react-native';
470
+
471
+ import Screen from '../../ui/components/Screen';
472
+
473
+ import { employeesFetch } from '../../ui/redux/uiActions';
474
+
475
+
476
+
477
+ const styles = StyleSheet.create({
478
+
479
+
480
+
481
+ });
482
+
483
+
484
+
485
+ class Home extends React.Component {
486
+
487
+ // Set the navigation options for `react-navigation`
488
+
489
+ static navigationOptions = {
490
+
491
+ headerTitle: 'Home',
492
+
493
+ };
494
+
495
+
496
+
497
+ componentWillMount() {
498
+
499
+ this.props.employeesFetch();
500
+
501
+
502
+
503
+ this.createDataSource(this.props);
504
+
505
+ }
506
+
507
+
508
+
509
+ componentWillReceiveProps(nextProps) {
510
+
511
+
512
+
513
+ this.createDataSource(nextProps);
514
+
515
+ }
516
+
517
+
518
+
519
+ createDataSource({ employees }) {
520
+
521
+ const ds = new ListView.DataSource({
522
+
523
+ rowHasChanged: (r1, r2) => r1 !==r2
524
+
525
+ });
526
+
527
+
528
+
529
+ this.dataSource = ds.cloneWithRows(employees);
530
+
531
+ }
532
+
533
+
534
+
535
+ render() {
536
+
537
+ console.log(this.props);
538
+
539
+
540
+
541
+ return (
542
+
543
+ <Screen>
544
+
545
+ <View>
546
+
547
+ <Text>Employee List</Text>
548
+
549
+ <Text>Employee List</Text>
550
+
551
+ <Text>Employee List</Text>
552
+
553
+ <Text>Employee List</Text>
554
+
555
+ </View>
556
+
557
+ </Screen>
558
+
559
+ );
560
+
561
+ }
562
+
563
+ }
564
+
565
+
566
+
567
+ const mapStateToProps = state => {
568
+
569
+ const employees = _.map(state.employees, (val, uid) => {
570
+
571
+ return { ...val, uid };
572
+
573
+ });
574
+
575
+
576
+
577
+ return { employees };
578
+
579
+ }
580
+
581
+
582
+
583
+ export default connect(mapStateToProps, { employeesFetch })(Home);
584
+
585
+ ```

1

Reduxの中身を追記しました

2018/02/11 12:58

投稿

yamady
yamady

スコア176

test CHANGED
File without changes
test CHANGED
@@ -4,6 +4,10 @@
4
4
 
5
5
 
6
6
 
7
+ アプリの内容は雇用者を管理して、情報を投稿するアプリを想定しています。
8
+
9
+
10
+
7
11
  ```
8
12
 
9
13
  Expected the reducer to be a function
@@ -22,18 +26,6 @@
22
26
 
23
27
  ```JavaScript
24
28
 
25
- /**
26
-
27
- * @flow
28
-
29
- *
30
-
31
- * This file is the main entry point into our app.
32
-
33
- * It is shared across both Android and iOS.
34
-
35
- */
36
-
37
29
  import React from 'react';
38
30
 
39
31
  import { StyleSheet, View } from 'react-native';
@@ -64,8 +56,6 @@
64
56
 
65
57
 
66
58
 
67
- // Configure `react-native-google-signin` with our client IDs
68
-
69
59
  GoogleSignin.configure({
70
60
 
71
61
  iosClientId: GOOGLE_SIGN_IN_IOS_CLIENT_ID,
@@ -88,20 +78,10 @@
88
78
 
89
79
 
90
80
 
91
- /*
92
-
93
- * We use flow type to validate the State of the component
94
-
95
- */
96
-
97
81
  type State = {
98
82
 
99
- // Whether Firebase is still checking if the user is logged in or out
100
-
101
83
  loading: boolean,
102
84
 
103
- // The Firebase user
104
-
105
85
  user?: Object,
106
86
 
107
87
  }
@@ -120,8 +100,6 @@
120
100
 
121
101
  super();
122
102
 
123
- // Set the default state of the component
124
-
125
103
  this.state = {
126
104
 
127
105
  loading: true,
@@ -200,28 +178,6 @@
200
178
 
201
179
  ```JavaScript
202
180
 
203
- /**
204
-
205
- * @flow
206
-
207
- *
208
-
209
- * This file configures the Redux store
210
-
211
- *
212
-
213
- * To keep things simple, and because Firebase already acts as a state management solution,
214
-
215
- * we are only using Redux for the following:
216
-
217
- *
218
-
219
- * 1) `redux-form` integration
220
-
221
- * 2) Basic UI state, i.e. the loading modal
222
-
223
- */
224
-
225
181
  import { createStore, combineReducers } from 'redux';
226
182
 
227
183
  import { reducer as formReducer } from 'redux-form';
@@ -230,6 +186,10 @@
230
186
 
231
187
  import uiReducer from '../ui/redux/uiReducer';
232
188
 
189
+ import employeeFormReducer from '../ui/redux/employeeFormReducer';
190
+
191
+ import employeeReducer from '../ui/redux/employeeReducer';
192
+
233
193
 
234
194
 
235
195
  const rootReducer = combineReducers({
@@ -238,6 +198,10 @@
238
198
 
239
199
  ui: uiReducer,
240
200
 
201
+ employeeForm: employeeFormReducer,
202
+
203
+ employees: employeeReducer
204
+
241
205
  });
242
206
 
243
207
 
@@ -255,3 +219,183 @@
255
219
 
256
220
 
257
221
  rootReducerの部分をstoreに変えてみたりもしました。
222
+
223
+
224
+
225
+ ## 追記
226
+
227
+
228
+
229
+ reduxを読み込んでいるスクリプトを追記します。
230
+
231
+
232
+
233
+ > uiReducer.js
234
+
235
+
236
+
237
+ ```JavaScript
238
+
239
+ type UiAction = {
240
+
241
+ type: 'ui/loading/hide' | 'ui/loading/show',
242
+
243
+ }
244
+
245
+
246
+
247
+ type UiReduxState = {
248
+
249
+ loading: boolean,
250
+
251
+ }
252
+
253
+
254
+
255
+ const initialState = {
256
+
257
+ loading: false,
258
+
259
+ };
260
+
261
+
262
+
263
+ export default (state: UiReduxState = initialState, action: UiAction): UiReduxState => {
264
+
265
+ switch (action.type) {
266
+
267
+ case 'ui/loading/hide':
268
+
269
+ return {
270
+
271
+ ...state,
272
+
273
+ loading: false,
274
+
275
+ };
276
+
277
+
278
+
279
+ case 'ui/loading/show':
280
+
281
+ return {
282
+
283
+ ...state,
284
+
285
+ loading: true,
286
+
287
+ };
288
+
289
+
290
+
291
+ default:
292
+
293
+ return state;
294
+
295
+ }
296
+
297
+ };
298
+
299
+
300
+
301
+ const isLoading = (state: { ui: UiReduxState }) => state.ui.loading;
302
+
303
+
304
+
305
+ export const Store = ({
306
+
307
+ isLoading,
308
+
309
+ });
310
+
311
+ ```
312
+
313
+
314
+
315
+ > employeeForm.js
316
+
317
+
318
+
319
+ ```JavaScript
320
+
321
+ type UiAction = {
322
+
323
+ type: 'employee_update',
324
+
325
+ type: 'employee_create'
326
+
327
+ }
328
+
329
+
330
+
331
+ const initialState = {
332
+
333
+ title: '',
334
+
335
+ category: '',
336
+
337
+ address: '',
338
+
339
+ price: ''
340
+
341
+ };
342
+
343
+
344
+
345
+ export default (state = initialState, action) => {
346
+
347
+ switch (action.type) {
348
+
349
+ case 'employee_update':
350
+
351
+ return {...state, [action.payload.prop]: action.payload.value };
352
+
353
+ case 'employee_create':
354
+
355
+ return initialState;
356
+
357
+ default:
358
+
359
+ return state;
360
+
361
+ }
362
+
363
+ };
364
+
365
+ ```
366
+
367
+ > employeeReducer.js
368
+
369
+
370
+
371
+ ```JavaScript
372
+
373
+ type UiAction = {
374
+
375
+ type: 'employees_fetch_success',
376
+
377
+ }
378
+
379
+
380
+
381
+ const initialState = {};
382
+
383
+
384
+
385
+ export default (state = initialState, action) => {
386
+
387
+ switch (action.type) {
388
+
389
+ case 'employees_fetch_success':
390
+
391
+ return action.payload;
392
+
393
+ default:
394
+
395
+ return state;
396
+
397
+ }
398
+
399
+ };
400
+
401
+ ```