Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,300 --> 00:00:05,420
So, what are custom hooks?
2
00:00:05,420 --> 00:00:08,160
And we need to clarify what they are
3
00:00:08,160 --> 00:00:10,570
before I can dive into the why.
4
00:00:10,570 --> 00:00:13,270
So, what are custom hooks?
5
00:00:13,270 --> 00:00:18,270
Custom hooks are, in the end, just regular functions
6
00:00:18,480 --> 00:00:21,970
just as the built-in hooks, like use state, are
7
00:00:21,970 --> 00:00:26,550
in the end just functions, but they are functions
8
00:00:26,550 --> 00:00:30,140
which can contain stateful logic.
9
00:00:30,140 --> 00:00:33,930
You can build custom hooks, these custom hook functions
10
00:00:33,930 --> 00:00:38,930
to outsource stateful logic into reusable functions.
11
00:00:39,870 --> 00:00:44,180
Unlike regular functions, custom hooks can use
12
00:00:44,180 --> 00:00:47,690
other React hooks, including other custom hooks.
13
00:00:47,690 --> 00:00:52,220
And they can, therefore, also leverage React state managed
14
00:00:52,220 --> 00:00:55,180
with use state or use reducer.
15
00:00:55,180 --> 00:00:58,670
They can access use effect and so on.
16
00:00:58,670 --> 00:01:02,770
With custom hooks, you can outsource logic,
17
00:01:02,770 --> 00:01:05,580
which you might be using in different components,
18
00:01:05,580 --> 00:01:08,200
into a custom hook, which you can then call
19
00:01:08,200 --> 00:01:11,210
from all these various components.
20
00:01:11,210 --> 00:01:14,980
So, it is simply a mechanism of reusing logic,
21
00:01:14,980 --> 00:01:19,510
just as regular functions are with the special thing
22
00:01:19,510 --> 00:01:22,150
that in these custom hook functions,
23
00:01:22,150 --> 00:01:25,950
you can use React hooks and other hooks.
24
00:01:25,950 --> 00:01:29,710
And that might, of course, still be a bit abstract.
25
00:01:29,710 --> 00:01:31,230
So, therefore, let me give you
26
00:01:31,230 --> 00:01:33,840
a concrete example which shows you
27
00:01:33,840 --> 00:01:37,070
why you might wanna explore custom hooks
28
00:01:37,070 --> 00:01:39,860
and how you then build a custom hook,
29
00:01:39,860 --> 00:01:42,203
step-by-step and how you use it.
2315
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.