﻿1
00:00:01,080 --> 00:00:04,920
‫Remember how I said earlier how rendering lists is one

2
00:00:04,920 --> 00:00:08,520
‫of the most common tasks in React development?

3
00:00:08,520 --> 00:00:11,790
‫Well, this application is no exception.

4
00:00:11,790 --> 00:00:15,693
‫And so let's now render the list of pecking items.

5
00:00:17,040 --> 00:00:21,390
‫And first of all, let's go to our CSS file

6
00:00:21,390 --> 00:00:23,890
‫because that's again where I pasted

7
00:00:25,020 --> 00:00:26,883
‫this array of initial items.

8
00:00:27,870 --> 00:00:29,643
‫So let's grab that.

9
00:00:32,250 --> 00:00:34,770
‫We can also close index.js

10
00:00:34,770 --> 00:00:36,820
‫and I will paste it here at the very top.

11
00:00:40,110 --> 00:00:42,540
‫So you see that we have once again

12
00:00:42,540 --> 00:00:45,660
‫an array with a few objects, and in this case

13
00:00:45,660 --> 00:00:49,410
‫each object describes one item to be packed.

14
00:00:49,410 --> 00:00:52,683
‫So each of them has an ID, a description, quantity,

15
00:00:53,835 --> 00:00:54,668
‫NT OD packed property

16
00:00:54,668 --> 00:00:59,430
‫which tells us whether this one has been packed or not.

17
00:00:59,430 --> 00:01:00,390
‫So based on this

18
00:01:00,390 --> 00:01:03,810
‫we will then display the item a little bit differently.

19
00:01:03,810 --> 00:01:07,290
‫So here, well here we don't have any.

20
00:01:07,290 --> 00:01:08,613
‫So here in the demo app.

21
00:01:09,540 --> 00:01:13,320
‫So you see right now it's not packed, but if it is packed

22
00:01:13,320 --> 00:01:15,873
‫then you see it is like strike through.

23
00:01:17,400 --> 00:01:20,940
‫Now okay, so let's now take these items here and

24
00:01:20,940 --> 00:01:23,643
‫render them as a list into our UI.

25
00:01:25,170 --> 00:01:26,610
‫So as the name says

26
00:01:26,610 --> 00:01:29,133
‫we're going to do that in the packing list.

27
00:01:30,060 --> 00:01:33,810
‫So first of all, let's again use semantic HTML

28
00:01:33,810 --> 00:01:37,680
‫and convert this diff into a UL.

29
00:01:37,680 --> 00:01:39,783
‫So into a unordered list.

30
00:01:41,880 --> 00:01:42,720
‫All right?

31
00:01:42,720 --> 00:01:46,140
‫And then immediately here we enter JavaScript mode

32
00:01:46,140 --> 00:01:49,635
‫because remember how we render lists in React?

33
00:01:49,635 --> 00:01:53,790
‫Well, we simply use the map method that we already know

34
00:01:53,790 --> 00:01:55,113
‫on the array.

35
00:01:56,400 --> 00:02:00,090
‫So initial items, and later on we will, of course

36
00:02:00,090 --> 00:02:03,810
‫then when we make this dynamic, use another array here.

37
00:02:03,810 --> 00:02:07,320
‫But again, for now here, we just want to render something

38
00:02:07,320 --> 00:02:08,673
‫so just to make this work.

39
00:02:10,890 --> 00:02:11,760
‫Okay?

40
00:02:11,760 --> 00:02:13,830
‫Then inside the map method

41
00:02:13,830 --> 00:02:17,463
‫each of the elements will be, let's say an item.

42
00:02:19,650 --> 00:02:21,480
‫All right? And then for each item

43
00:02:21,480 --> 00:02:25,380
‫what we want to render is an item component.

44
00:02:25,380 --> 00:02:27,030
‫So let's immediately write that here

45
00:02:27,030 --> 00:02:30,303
‫and we will then create the item component in a minute.

46
00:02:31,440 --> 00:02:36,153
‫So item, and then we passed in as a prop, the entire item.

47
00:02:38,070 --> 00:02:43,070
‫So item and then item again, let's close this here.

48
00:02:44,400 --> 00:02:47,460
‫So you see we have a lot of items here.

49
00:02:47,460 --> 00:02:50,190
‫So the name of the component, the name of the prop,

50
00:02:50,190 --> 00:02:52,710
‫and then here the object itself

51
00:02:52,710 --> 00:02:54,900
‫which, remember, is the argument

52
00:02:54,900 --> 00:02:59,700
‫of this callback function in each iteration over this array.

53
00:02:59,700 --> 00:03:01,833
‫So nothing new here at this point, I hope.

54
00:03:02,670 --> 00:03:05,970
‫So, a gift is a safe, but of course item is not defined.

55
00:03:05,970 --> 00:03:09,450
‫So let's quickly take care of that.

56
00:03:09,450 --> 00:03:13,740
‫And now here we need to accept the props, right?

57
00:03:13,740 --> 00:03:18,150
‫So we can do it like this, remember, but even better

58
00:03:18,150 --> 00:03:19,977
‫we can immediately destructure this

59
00:03:19,977 --> 00:03:22,260
‫and then give it the name here

60
00:03:22,260 --> 00:03:25,770
‫of the prop that we passed in, which is item.

61
00:03:25,770 --> 00:03:27,630
‫And again, it could be anything.

62
00:03:27,630 --> 00:03:32,630
‫It could be object like O, B, G, or X or anything.

63
00:03:32,790 --> 00:03:35,910
‫But yeah, it's easier to just call it item here

64
00:03:35,910 --> 00:03:37,710
‫because that's what it is.

65
00:03:37,710 --> 00:03:40,593
‫It's just a packing item, so to say.

66
00:03:42,360 --> 00:03:46,740
‫So here, this item should be now an LI element.

67
00:03:46,740 --> 00:03:50,790
‫So a list item, because that's usually what direct children

68
00:03:50,790 --> 00:03:54,960
‫of the UI or of the UL element should be.

69
00:03:54,960 --> 00:03:58,176
‫And then just to start, just to see if it's working

70
00:03:58,176 --> 00:04:03,150
‫let's simply render, I think it's called description.

71
00:04:03,150 --> 00:04:04,770
‫Yes, that's it.

72
00:04:04,770 --> 00:04:06,750
‫We'll just copy that actually.

73
00:04:06,750 --> 00:04:10,110
‫So item dot description, give it a safe.

74
00:04:10,110 --> 00:04:11,940
‫And there it is.

75
00:04:11,940 --> 00:04:14,280
‫So we have passports and socks.

76
00:04:14,280 --> 00:04:16,931
‫Now the styling here is a little bit off.

77
00:04:16,931 --> 00:04:18,780
‫And the reason for that is

78
00:04:18,780 --> 00:04:23,695
‫that here I actually did a mistake in the HTML.

79
00:04:23,695 --> 00:04:28,263
‫So here let's actually create a diff, and then

80
00:04:29,610 --> 00:04:33,663
‫it's this diff that is supposed to have the list class.

81
00:04:35,400 --> 00:04:36,450
‫All right?

82
00:04:36,450 --> 00:04:38,790
‫And the reason for that is that later on

83
00:04:38,790 --> 00:04:42,540
‫we will have another element in here for these filters.

84
00:04:42,540 --> 00:04:46,023
‫So we will have a diff for these two things down here.

85
00:04:47,970 --> 00:04:49,480
‫All right.

86
00:04:49,480 --> 00:04:51,090
‫So of course for me, that's easy to see now

87
00:04:51,090 --> 00:04:54,030
‫because I already built the app beforehand.

88
00:04:54,030 --> 00:04:56,550
‫But once you start building your apps on your own

89
00:04:56,550 --> 00:04:58,650
‫there will be a lot more back and forth

90
00:04:58,650 --> 00:05:00,900
‫which of course I cannot do here in this course

91
00:05:00,900 --> 00:05:03,333
‫because then it will take just forever.

92
00:05:04,890 --> 00:05:09,570
‫Okay, but anyway, let's now add some more here.

93
00:05:09,570 --> 00:05:12,030
‫So we don't just want a description

94
00:05:12,030 --> 00:05:17,030
‫we also want this icon here for the leading.

95
00:05:17,310 --> 00:05:19,290
‫And later we will want this checkbox

96
00:05:19,290 --> 00:05:21,573
‫but let's leave that for later actually.

97
00:05:22,800 --> 00:05:26,670
‫So here, let's create a spin element.

98
00:05:26,670 --> 00:05:31,670
‫So for the text, let's grab that, paste that here.

99
00:05:32,580 --> 00:05:35,973
‫And then we also want the item dot.

100
00:05:37,260 --> 00:05:40,773
‫Let's see, it's the item dot quantity exactly.

101
00:05:40,773 --> 00:05:44,580
‫So item dot quantity.

102
00:05:44,580 --> 00:05:48,300
‫And notice how sometimes prettier creates like

103
00:05:48,300 --> 00:05:51,060
‫these empty strings here in our JSX

104
00:05:51,060 --> 00:05:53,193
‫so many times this is not necessary.

105
00:05:54,397 --> 00:05:55,890
‫So just get rid of that.

106
00:05:55,890 --> 00:05:58,293
‫And now finally, we need delete button.

107
00:06:00,900 --> 00:06:04,530
‫And for now, we won't attach any event handler here

108
00:06:04,530 --> 00:06:09,030
‫but we will just place an icon here in the form of an emoji.

109
00:06:09,030 --> 00:06:10,743
‫So maybe like that.

110
00:06:11,610 --> 00:06:13,143
‫So this X right here.

111
00:06:14,169 --> 00:06:16,234
‫And again, if you can't make this work

112
00:06:16,234 --> 00:06:21,087
‫then you can just write the X like this or also like this.

113
00:06:22,440 --> 00:06:24,213
‫So that would work as well.

114
00:06:26,460 --> 00:06:30,450
‫Alright, so this has now been rendered here based

115
00:06:30,450 --> 00:06:31,710
‫off this list.

116
00:06:31,710 --> 00:06:35,490
‫And if we duplicate this and add something else here

117
00:06:35,490 --> 00:06:40,490
‫like a charger, one charger, then there it is.

118
00:06:41,760 --> 00:06:45,813
‫Now to finish, let's just mark one of them as packed.

119
00:06:46,890 --> 00:06:48,510
‫Make this one true

120
00:06:48,510 --> 00:06:51,780
‫so that we can add some additional styling here.

121
00:06:51,780 --> 00:06:55,642
‫So we want to basically have some strike through there.

122
00:06:55,642 --> 00:06:58,440
‫So that's simple stuff.

123
00:06:58,440 --> 00:07:00,600
‫So let's come here to the item.

124
00:07:00,600 --> 00:07:04,590
‫And here we will now conditionally add some styling.

125
00:07:04,590 --> 00:07:07,830
‫So instead of conditionally adding a class here

126
00:07:07,830 --> 00:07:11,430
‫I want to conditionally simply add some style.

127
00:07:11,430 --> 00:07:13,440
‫So let's write style

128
00:07:13,440 --> 00:07:16,410
‫and then it immediately enters JavaScript mode.

129
00:07:16,410 --> 00:07:19,800
‫But now I will not immediately write the object

130
00:07:19,800 --> 00:07:21,690
‫of CSS properties.

131
00:07:21,690 --> 00:07:24,887
‫Instead, let's actually use the ary operator to

132
00:07:24,887 --> 00:07:29,433
‫decide which object the style should actually receive.

133
00:07:30,270 --> 00:07:35,270
‫So if item is packed, and here we don't really

134
00:07:35,400 --> 00:07:39,090
‫need a condition because this is already a bullion.

135
00:07:39,090 --> 00:07:40,440
‫So if it is packed

136
00:07:40,440 --> 00:07:44,550
‫then we want an object which will contain some CSS

137
00:07:44,550 --> 00:07:47,400
‫for the strike through, but if not,

138
00:07:47,400 --> 00:07:49,230
‫so if the item is not packed,

139
00:07:49,230 --> 00:07:52,530
‫then we will want to return this empty object.

140
00:07:52,530 --> 00:07:54,993
‫And so then no styles are going to be applied.

141
00:07:56,640 --> 00:07:59,730
‫So the CSS property that we're looking for

142
00:07:59,730 --> 00:08:03,250
‫is called text decoration

143
00:08:04,200 --> 00:08:07,983
‫and let's set it to line through like this.

144
00:08:11,356 --> 00:08:13,053
‫And that worked quite nice.

145
00:08:14,520 --> 00:08:19,520
‫All right, so let's try another one just for fun.

146
00:08:19,950 --> 00:08:21,510
‫And yeah, immediately you see

147
00:08:21,510 --> 00:08:23,793
‫that it gets strike through as well.

148
00:08:24,660 --> 00:08:26,640
‫So this was yet another way

149
00:08:26,640 --> 00:08:29,430
‫of using the turnaround operator to conditionally

150
00:08:29,430 --> 00:08:31,080
‫set some style here.

151
00:08:31,080 --> 00:08:33,870
‫So you see that we have a lot of freedom in React,

152
00:08:33,870 --> 00:08:36,570
‫and again we simply use the JavaScript tools

153
00:08:36,570 --> 00:08:39,483
‫that we already have for this kind of stuff.

