質問編集履歴

2

追記の追加

2020/01/30 04:33

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -391,3 +391,179 @@
391
391
  export default HistoryReducer
392
392
 
393
393
  ```
394
+
395
+ ## 追記
396
+
397
+
398
+
399
+ Reducerを下記の様に修正いたしました。
400
+
401
+ ```
402
+
403
+ import * as actionTypes from '../utils/actionTypes'
404
+
405
+ import * as actions from '../actions'
406
+
407
+
408
+
409
+ type Actions = (
410
+
411
+ | ReturnType<typeof actions.setHistory>
412
+
413
+ )
414
+
415
+
416
+
417
+ type History = {
418
+
419
+ date: string,
420
+
421
+ store: actions.iStore,
422
+
423
+ company: actions.iCompany,
424
+
425
+ products: actions.Product[]
426
+
427
+ }
428
+
429
+
430
+
431
+ interface iState {
432
+
433
+ histories: History[]
434
+
435
+ }
436
+
437
+
438
+
439
+ const initialState: iState = {
440
+
441
+ histories: []
442
+
443
+ }
444
+
445
+
446
+
447
+ const HistoryReducer = (state: iState = initialState, action: Actions) => {
448
+
449
+ switch (action.type) {
450
+
451
+ case actionTypes.SET_HISTORY:
452
+
453
+ return Object.assign({}, state, {
454
+
455
+ state: action.payload.histories
456
+
457
+ })
458
+
459
+ }
460
+
461
+
462
+
463
+ return state
464
+
465
+ }
466
+
467
+
468
+
469
+ export default HistoryReducer
470
+
471
+ ```
472
+
473
+ actionに記述していたinterface iProductも下記の様に修正いたしました。
474
+
475
+ ```
476
+
477
+ // 購入履歴
478
+
479
+ export interface iStore {
480
+
481
+ id: number,
482
+
483
+ image: string,
484
+
485
+ address: string
486
+
487
+ }
488
+
489
+ export interface iCompany {
490
+
491
+ id: number,
492
+
493
+ name: string
494
+
495
+ }
496
+
497
+ export type Product = {
498
+
499
+ id: number,
500
+
501
+ name: string,
502
+
503
+ price: number
504
+
505
+ }
506
+
507
+ ```
508
+
509
+ gRPCのレスポンスは以下の様に返ってきます。
510
+
511
+ ```
512
+
513
+ (4) [{…}, {…}, {…}, {…}]
514
+
515
+ 0:
516
+
517
+ date: "2020/01/29"
518
+
519
+ store: {id: 1, image: "", address: "滋賀県彦根市"}
520
+
521
+ company: {id: 1, name: "セブンイレブン"}
522
+
523
+ product:
524
+
525
+ id: 1
526
+
527
+ name: "コーラ"
528
+
529
+ price: 150
530
+
531
+ __proto__: Object
532
+
533
+ __proto__: Object
534
+
535
+ 1: {date: "2020/01/29", store: {…}, company: {…}, product: {…}}
536
+
537
+ 2: {date: "2020/01/29", store: {…}, company: {…}, product: {…}}
538
+
539
+ 3: {date: "2020/01/29", store: {…}, company: {…}, product: {…}}
540
+
541
+ length: 4
542
+
543
+ ```
544
+
545
+ 上記には記述されていませんが、case actionTypes.SET_HISTORYでreturnする前に
546
+
547
+ ```
548
+
549
+ Object.assign({}, state, {
550
+
551
+ state: action.payload.histories
552
+
553
+ })
554
+
555
+ console.log(state)
556
+
557
+ ```
558
+
559
+ をすると下記の様に表示されます。
560
+
561
+ ```
562
+
563
+ {histories: Array(0)}
564
+
565
+ histories: Array(0)
566
+
567
+ length: 0
568
+
569
+ ```

1

タイトルの変更

2020/01/30 04:33

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- 質問 タグ ユーザー 3次元配列をReducerのinitialStateとして記述する。
1
+ ReduxのReducerの3次元配列の更新が上手くいきません
test CHANGED
File without changes