Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,820 --> 00:00:08,110
We've made a lot of progress with our header but there's still one thing that it doesn't do actually
2
00:00:08,110 --> 00:00:09,770
navigate.
3
00:00:09,850 --> 00:00:17,530
We still haven't set up the actual navigation system for the header tabs to actually change the page
4
00:00:17,530 --> 00:00:26,020
that we're on as well as the display which page we have currently selected before we get into setting
5
00:00:26,020 --> 00:00:30,380
up react router and handling the actual navigation.
6
00:00:30,400 --> 00:00:37,830
Let's just set up the functionality that will keep track of which page we're on if you remember from
7
00:00:37,830 --> 00:00:46,590
the documentation walkthrough you'll remember that the tabs component is allowed a value prop and this
8
00:00:46,590 --> 00:00:52,070
value can be the index of the currently selected tab.
9
00:00:52,110 --> 00:00:59,370
So if I were to pass in a zero here for the value and his save you'll see the page refresh.
10
00:00:59,490 --> 00:01:09,480
And now our first tab in this case the Home tab is now highlighted the text and it has a little indicator
11
00:01:09,480 --> 00:01:10,770
underneath as well.
12
00:01:11,830 --> 00:01:19,750
If we were to change that active value from 0 to a 1 and then save then now you can see the services
13
00:01:19,750 --> 00:01:27,440
tab is selected so that's how the tabs component maintains which tab is currently selected.
14
00:01:27,560 --> 00:01:34,340
But we need to set it up to programmatically maintain that because right now if you try and switch it
15
00:01:34,340 --> 00:01:40,350
doesn't even go to a different tab or do anything at all.
16
00:01:40,380 --> 00:01:43,680
So let's look this up to actually work.
17
00:01:44,100 --> 00:01:49,350
If you remember from the documentation we're actually going to use a hook.
18
00:01:49,350 --> 00:02:00,510
And so we will create a constant and use the hook syntax to create a value and a set value function
19
00:02:00,540 --> 00:02:09,230
that will be able to change our default state set with use state of 0.
20
00:02:09,290 --> 00:02:11,840
Now we actually haven't imported you state.
21
00:02:11,870 --> 00:02:14,360
You can see you state is not defined.
22
00:02:14,360 --> 00:02:20,650
So let's go up to the top and next to inside of actually our ReACT import.
23
00:02:20,750 --> 00:02:28,070
Put a comma and then a pair of brackets so that we can d structure out a another import specifically
24
00:02:28,310 --> 00:02:32,510
and we'll do that to the use state hook.
25
00:02:32,600 --> 00:02:35,150
Now they use a state is defined.
26
00:02:35,210 --> 00:02:46,140
We're setting up a value on our state equal to zero to begin with if we now pass that value here to
27
00:02:46,140 --> 00:02:56,030
our value prop on the tabs and then we hit save you will see that now our first tab is selected.
28
00:02:56,040 --> 00:03:00,840
We still however don't have a way to change which tab we're on.
29
00:03:00,840 --> 00:03:10,610
And so to do that we need to add in on change handler to the tabs component we can open that up and
30
00:03:10,610 --> 00:03:18,950
then let's come up here to define what that on change handler will be and we can call this handle change
31
00:03:19,250 --> 00:03:28,040
which is set equal to a function which will take any event as well as the value being passed through.
32
00:03:28,040 --> 00:03:35,270
Which in this case is the index of the selected tab and then we're going to open this arrow function
33
00:03:35,330 --> 00:03:45,200
up and to use the set value hook to change the state of our selected tab to the newly selected tab at
34
00:03:45,200 --> 00:03:47,630
the new value.
35
00:03:47,650 --> 00:03:55,250
Now we have to actually pass that function to our on change prop as the handle change function.
36
00:03:55,330 --> 00:04:03,310
And now if we go ahead and save this our page will reload and if we come up and try to switch tabs we
37
00:04:03,310 --> 00:04:10,540
see our little indicator is animated over as well as the tab is correctly highlighted.
38
00:04:10,630 --> 00:04:17,200
It's really cool how easy they made that to set up and really just how nice that little bit of functionality
39
00:04:17,200 --> 00:04:18,730
actually is.
40
00:04:19,340 --> 00:04:25,370
One thing I don't necessarily like about it though is how we have this little orange line underneath
41
00:04:25,430 --> 00:04:26,370
the tab.
42
00:04:26,420 --> 00:04:31,550
I think that in some designs that could look really nice depending on how you use it.
43
00:04:31,670 --> 00:04:40,860
But I think for my design I'd really prefer not to have it at all material UI provides a really easy
44
00:04:40,860 --> 00:04:48,960
way to actually get rid of that indicator or actually just hide it really well by setting on the tabs
45
00:04:48,960 --> 00:04:59,390
component a another property which is indicator color and we're going to set this equal to primary now.
46
00:04:59,460 --> 00:05:06,330
Right now it's set to our default of secondary and you can see that orange but if we go ahead and save
47
00:05:06,360 --> 00:05:14,370
with the indicator color set to primary you'll see that now the indicator is gone and if you're savvy
48
00:05:14,400 --> 00:05:20,640
you'll know that obviously we just changed the color to primary and that the color of the background
49
00:05:20,670 --> 00:05:22,560
is our primary color as well.
50
00:05:22,560 --> 00:05:27,990
And so the little indicator is actually just hidden out of view.
51
00:05:28,060 --> 00:05:35,530
So now our application will keep track of and display the currently selected page which lays the groundwork
52
00:05:35,530 --> 00:05:42,820
for enabling us to actually then change which page we are on using react router in the next video.
6082
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.