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,100
So what is Redux?
2
00:00:05,100 --> 00:00:09,850
Redux is a state management system for a cross-component
3
00:00:09,850 --> 00:00:12,140
or app-wide state.
4
00:00:12,140 --> 00:00:16,810
So it helps us manage state, data that changes
5
00:00:16,810 --> 00:00:18,850
and affects our application
6
00:00:18,850 --> 00:00:20,880
and what we display on the screen.
7
00:00:20,880 --> 00:00:24,890
It helps us manage such data across multiple components
8
00:00:24,890 --> 00:00:27,150
or even the complete app.
9
00:00:27,150 --> 00:00:29,710
Now just to make sure that we're all on the same page
10
00:00:29,710 --> 00:00:34,240
we did of course use state a lot in this course already
11
00:00:34,240 --> 00:00:39,230
with the use state hook or also with use reducer.
12
00:00:39,230 --> 00:00:43,490
And indeed those hooks exist to allow us to manage data
13
00:00:43,490 --> 00:00:46,230
that typically changes for example,
14
00:00:46,230 --> 00:00:50,590
when the user clicks a button and we're changes to that data
15
00:00:50,590 --> 00:00:55,240
then typically lead to the UI being updated.
16
00:00:55,240 --> 00:00:59,860
We use React's State Management Hooks like use state
17
00:00:59,860 --> 00:01:03,280
so that we can tell React that some data changed
18
00:01:03,280 --> 00:01:06,670
and so that it then updates the UI for us.
19
00:01:06,670 --> 00:01:09,170
That's what we did through out this course.
20
00:01:09,170 --> 00:01:11,330
And that is what state is all about.
21
00:01:11,330 --> 00:01:14,368
But we can split the definition of state
22
00:01:14,368 --> 00:01:18,610
into three main kinds of state.
23
00:01:18,610 --> 00:01:22,780
We have a local state and we also have cross-component
24
00:01:22,780 --> 00:01:24,670
and app-wide state.
25
00:01:24,670 --> 00:01:27,150
Now these are not hard definitions
26
00:01:27,150 --> 00:01:30,280
these are just definitions which you will see a lot
27
00:01:30,280 --> 00:01:34,440
or these are separations of state which you see a lot
28
00:01:34,440 --> 00:01:37,050
and therefore I also like to use them.
29
00:01:37,050 --> 00:01:39,320
Now what is a local state?
30
00:01:39,320 --> 00:01:44,320
Local state is state so data which changes that affects DUI
31
00:01:44,970 --> 00:01:47,790
which belongs to a single component.
32
00:01:47,790 --> 00:01:50,790
And for example, if we listen to a user input
33
00:01:50,790 --> 00:01:53,910
and we use useState to store that input
34
00:01:53,910 --> 00:01:57,510
with every keystroke in a state variable.
35
00:01:57,510 --> 00:02:02,030
Or we have a button that toggles some detailed field.
36
00:02:02,030 --> 00:02:04,710
So if we click that button we show the details
37
00:02:04,710 --> 00:02:06,910
if we click it again we hide them.
38
00:02:06,910 --> 00:02:09,669
That would be local state.
39
00:02:09,669 --> 00:02:12,960
And typically we manage such local state
40
00:02:12,960 --> 00:02:16,340
inside of a component with useState
41
00:02:16,340 --> 00:02:20,193
or if it's more complex maybe with useReducer.
42
00:02:21,450 --> 00:02:24,610
Now we also often have state that affects not
43
00:02:24,610 --> 00:02:28,690
just one component but multiple components.
44
00:02:28,690 --> 00:02:30,980
That would be cross component state.
45
00:02:30,980 --> 00:02:33,700
For example, if we have a button that opens
46
00:02:33,700 --> 00:02:38,430
or closes a modal overlay such a modal component
47
00:02:38,430 --> 00:02:41,100
might affect multiple components
48
00:02:41,100 --> 00:02:45,640
and the trigger for opening the modal is per definition
49
00:02:45,640 --> 00:02:47,310
not inside of the modal.
50
00:02:47,310 --> 00:02:49,920
On the apprehend the modal might be closed
51
00:02:49,920 --> 00:02:53,490
by clicking a button which is inside of that modal.
52
00:02:53,490 --> 00:02:56,500
So then we have multiple components working together
53
00:02:56,500 --> 00:02:59,480
to display and hide a modal.
54
00:02:59,480 --> 00:03:02,970
And we can also implement that with useState
55
00:03:02,970 --> 00:03:07,130
or useReducer we then just need to pass props around
56
00:03:07,130 --> 00:03:09,870
so we need to build those prop chains
57
00:03:09,870 --> 00:03:13,820
or do this prop drilling as it's also called
58
00:03:13,820 --> 00:03:17,410
where we pass drops across multiple components
59
00:03:17,410 --> 00:03:20,728
where we also might pass functions as props
60
00:03:20,728 --> 00:03:22,730
across multiple components
61
00:03:22,730 --> 00:03:25,850
so that these different components can work together
62
00:03:25,850 --> 00:03:28,210
and manage state together.
63
00:03:28,210 --> 00:03:30,120
And that's not bad or anything like that
64
00:03:30,120 --> 00:03:33,800
it's just a little bit more complex than local state.
65
00:03:33,800 --> 00:03:36,160
And sometimes we also have State
66
00:03:36,160 --> 00:03:39,620
that does not just affect multiple components
67
00:03:39,620 --> 00:03:43,670
but basically all components of an application.
68
00:03:43,670 --> 00:03:48,370
Now when that happens we could call this app-wide state
69
00:03:48,370 --> 00:03:52,480
and an example here would be user authentication.
70
00:03:52,480 --> 00:03:56,400
If I log in we might need to change the navigation bar
71
00:03:56,400 --> 00:03:59,320
because we now show new options
72
00:03:59,320 --> 00:04:02,470
and we also certainly affect a lot of other components
73
00:04:02,470 --> 00:04:04,923
which now show more or less data.
74
00:04:05,830 --> 00:04:08,840
So that would be an example for app-wide state.
75
00:04:08,840 --> 00:04:12,670
And we can also manage this with the useState, useReducer
76
00:04:12,670 --> 00:04:14,950
and then by passing state values
77
00:04:14,950 --> 00:04:18,310
and updating functions around full props.
78
00:04:18,310 --> 00:04:20,470
That's what we did through out this course
79
00:04:20,470 --> 00:04:23,010
and the data of course works.
80
00:04:23,010 --> 00:04:26,060
Now for cross-component and app-wide state
81
00:04:26,060 --> 00:04:29,790
passing around data and updating function fruit props
82
00:04:29,790 --> 00:04:32,130
can become cumbersome though.
83
00:04:32,130 --> 00:04:35,060
And that's why we did learn about React Context
84
00:04:35,060 --> 00:04:36,440
before in the course.
85
00:04:36,440 --> 00:04:40,140
React Context is a built in feature in React
86
00:04:40,140 --> 00:04:42,550
that makes managing cross-component
87
00:04:42,550 --> 00:04:44,930
or application wide state easier.
88
00:04:44,930 --> 00:04:47,820
So that's one way of simplifying cross-component
89
00:04:47,820 --> 00:04:50,210
and app-wide state management.
90
00:04:50,210 --> 00:04:52,940
Redux solves the same problem.
91
00:04:52,940 --> 00:04:57,940
So both React Context and Redux are there to help us manage
92
00:04:58,170 --> 00:05:01,390
such cross-component or app-wide States.
93
00:05:01,390 --> 00:05:04,610
And that of course brings up an important question.
94
00:05:04,610 --> 00:05:09,210
Why do we need Redux if we already have React Context
95
00:05:09,210 --> 00:05:12,493
for managing state that affects multiple components?
7669
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.