Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,150 --> 00:00:05,590
So, let me introduce the solution to you.
2
00:00:05,590 --> 00:00:09,890
What if we would use a dirty little trick?
3
00:00:09,890 --> 00:00:12,040
Here in my components folder,
4
00:00:12,040 --> 00:00:14,960
I'll add a new sub folder helpers.
5
00:00:14,960 --> 00:00:18,170
I'll name it helpers because debt best describes
6
00:00:18,170 --> 00:00:20,403
which kind of component I'm going to add.
7
00:00:21,460 --> 00:00:24,800
I'm going to add a wrapper
8
00:00:27,290 --> 00:00:30,550
component. I'll name the file wrapper JS.
9
00:00:30,550 --> 00:00:33,980
And in there, I won't even import React
10
00:00:33,980 --> 00:00:37,240
because I'm not going to write any JSX code in there.
11
00:00:37,240 --> 00:00:39,980
Instead, I'll just create my wrapper component,
12
00:00:39,980 --> 00:00:42,490
get props and have my function body,
13
00:00:42,490 --> 00:00:46,540
and export this wrapper.
14
00:00:46,540 --> 00:00:49,150
And now you might be wondering what I'm going to do here
15
00:00:49,150 --> 00:00:52,560
if I'm not writing any JSX code.
16
00:00:52,560 --> 00:00:56,870
Well, I'll just return props.children.
17
00:00:56,870 --> 00:01:00,410
Remember the children prop holds all the content
18
00:01:00,410 --> 00:01:03,310
you're passing between the opening and closing tag
19
00:01:03,310 --> 00:01:05,003
off your custom component.
20
00:01:05,990 --> 00:01:10,990
Now it is valid in a component to just return that content
21
00:01:11,830 --> 00:01:15,190
which you got between the opening and closing text.
22
00:01:15,190 --> 00:01:17,030
And now I can import my wrapper,
23
00:01:17,030 --> 00:01:19,570
for example, here in add user,
24
00:01:19,570 --> 00:01:24,570
I can import wrapper from helpers, wrapper.
25
00:01:26,080 --> 00:01:29,320
And I can use it as a regular react component.
26
00:01:29,320 --> 00:01:32,340
So I can go down there and replace my div,
27
00:01:32,340 --> 00:01:33,550
which has no other meaning
28
00:01:33,550 --> 00:01:38,550
than fulfilling this JSX requirement with my wrapper.
29
00:01:39,020 --> 00:01:41,110
So I'm using my rapper component here
30
00:01:41,110 --> 00:01:43,010
and just to make this really clear again,
31
00:01:43,010 --> 00:01:45,490
this is basically an empty component.
32
00:01:45,490 --> 00:01:49,990
Everything it does is that it returns props children.
33
00:01:49,990 --> 00:01:54,240
But this is enough to fulfill this requirement JSX has.
34
00:01:54,240 --> 00:01:58,330
If I save this my application still works just fine.
35
00:01:58,330 --> 00:02:01,060
And it works just fine because an add user,
36
00:02:01,060 --> 00:02:03,460
we have a wrapping element.
37
00:02:03,460 --> 00:02:06,570
Sure, it's an element which won't render
38
00:02:06,570 --> 00:02:08,900
anything to the dom, but the requirement
39
00:02:08,900 --> 00:02:12,020
is not that there must be one root component
40
00:02:12,020 --> 00:02:13,920
being rendered to the dom.
41
00:02:13,920 --> 00:02:18,130
The requirement just is, that there must be one root element
42
00:02:18,130 --> 00:02:22,220
that you return or that you store in a constant or variable.
43
00:02:22,220 --> 00:02:23,510
And that's what we're doing here.
44
00:02:23,510 --> 00:02:26,260
We have one root element the wrapper,
45
00:02:26,260 --> 00:02:28,810
and what we pass into that wrapper,
46
00:02:28,810 --> 00:02:31,943
may be adjacent, that is okay as I explained.
47
00:02:32,790 --> 00:02:35,130
Now of course all that content is taken
48
00:02:35,130 --> 00:02:37,820
and just returned here, but that's also okay
49
00:02:37,820 --> 00:02:39,550
because in this return statement,
50
00:02:39,550 --> 00:02:42,360
I technically still only returned one thing,
51
00:02:42,360 --> 00:02:45,660
I return the value in props children.
52
00:02:45,660 --> 00:02:48,560
And this can be tough to wrap your head around
53
00:02:48,560 --> 00:02:52,000
but this is just a technical requirement of JavaScript
54
00:02:52,000 --> 00:02:54,040
around which we're working here.
55
00:02:54,040 --> 00:02:56,430
I just work around that requirement
56
00:02:56,430 --> 00:02:58,860
by returning one thing here,
57
00:02:58,860 --> 00:03:00,830
and one thing here.
58
00:03:00,830 --> 00:03:03,810
And of course what we get here in props children
59
00:03:03,810 --> 00:03:06,160
will be that adjacent content,
60
00:03:06,160 --> 00:03:07,640
but that will not be a problem
61
00:03:07,640 --> 00:03:11,800
because I never directly returned that in my code.
62
00:03:11,800 --> 00:03:14,810
And this will therefore work just fine.
63
00:03:14,810 --> 00:03:19,340
This will not cause any errors as you can clearly tell.
64
00:03:19,340 --> 00:03:22,710
Now that's a nice little trick for solving this problem.
65
00:03:22,710 --> 00:03:25,290
Because if we now have a look at the elements tab
66
00:03:25,290 --> 00:03:28,770
and therefore at the dom, which is actually being rendered,
67
00:03:28,770 --> 00:03:32,940
we see that if I inspect my add form component,
68
00:03:32,940 --> 00:03:34,310
here's my form,
69
00:03:34,310 --> 00:03:35,960
we see there is a div around it,
70
00:03:35,960 --> 00:03:38,880
but that's just this card div.
71
00:03:38,880 --> 00:03:41,340
But what we also see is if I click Add user,
72
00:03:41,340 --> 00:03:43,590
that this modal div is being added.
73
00:03:43,590 --> 00:03:47,230
But around that, we do have a wrapping div,
74
00:03:47,230 --> 00:03:51,437
but this is actually the div coming from the app component
75
00:03:51,437 --> 00:03:53,790
where I also have the wrapping div.
76
00:03:53,790 --> 00:03:57,810
This is not coming from inside the add user component.
77
00:03:57,810 --> 00:03:59,450
Instead from inside there,
78
00:03:59,450 --> 00:04:02,060
nothing is being rendered into real dom.
79
00:04:02,060 --> 00:04:05,630
We got the card and above that, nothing.
80
00:04:05,630 --> 00:04:07,770
Because again, this div which is above it
81
00:04:07,770 --> 00:04:09,990
is coming from the app component.
82
00:04:09,990 --> 00:04:12,313
And that is of course pretty sweet.
6521
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.