All language subtitles for 021 Working with Query Parameters_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian Download
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:02,070 --> 00:00:04,850 Lots of features were added already. 2 00:00:04,850 --> 00:00:08,220 Now I wanna dive into query parameters. 3 00:00:08,220 --> 00:00:10,770 Query parameters are special parameters 4 00:00:10,770 --> 00:00:12,640 which you find on some URLs 5 00:00:12,640 --> 00:00:14,760 at the end of the URLs. 6 00:00:14,760 --> 00:00:15,720 On some URLs, 7 00:00:15,720 --> 00:00:17,280 you have a question mark. 8 00:00:17,280 --> 00:00:20,750 And then, thereafter you have parameter pairs, 9 00:00:20,750 --> 00:00:23,290 which basically pass extra data 10 00:00:23,290 --> 00:00:25,890 into the page that was loaded. 11 00:00:25,890 --> 00:00:30,420 The difference compared to regular route parameters, 12 00:00:30,420 --> 00:00:32,910 like our quoteId parameter, 13 00:00:32,910 --> 00:00:35,300 is that the regular parameters, 14 00:00:35,300 --> 00:00:38,280 like quoteId, are mandatory. 15 00:00:38,280 --> 00:00:40,840 So, this QuoteDetail page is only loaded 16 00:00:40,840 --> 00:00:41,990 if we have an ID, 17 00:00:41,990 --> 00:00:44,490 if we have this segment. 18 00:00:44,490 --> 00:00:47,300 Whereas query parameters are optional. 19 00:00:47,300 --> 00:00:48,960 The question mark thing here 20 00:00:48,960 --> 00:00:51,190 does not change the route matching. 21 00:00:51,190 --> 00:00:54,580 It has no impact on which route is matched. 22 00:00:54,580 --> 00:00:56,730 But whichever route is matched 23 00:00:56,730 --> 00:00:59,900 then has access to that query parameter data 24 00:00:59,900 --> 00:01:02,850 to, for example, change the behavior of the page 25 00:01:02,850 --> 00:01:04,550 that was loaded. 26 00:01:04,550 --> 00:01:07,340 And what could be a changed behavior? 27 00:01:07,340 --> 00:01:08,360 Well, for example, 28 00:01:08,360 --> 00:01:11,450 here on this quote list page here, 29 00:01:11,450 --> 00:01:14,120 we might wanna implement sorting. 30 00:01:14,120 --> 00:01:18,330 So that our quotes are sorted in ascending 31 00:01:18,330 --> 00:01:21,210 or descending order by ID 32 00:01:21,210 --> 00:01:24,263 and therefore by age, for example. 33 00:01:25,110 --> 00:01:26,460 For this, I'll first of all 34 00:01:26,460 --> 00:01:29,650 add such a sorting functionality. 35 00:01:29,650 --> 00:01:32,680 So, some logic to sort the components. 36 00:01:32,680 --> 00:01:34,470 And then as a second step, 37 00:01:34,470 --> 00:01:37,430 I wanna set and use query parameters 38 00:01:37,430 --> 00:01:39,860 to save the current sorting. 39 00:01:39,860 --> 00:01:41,940 So that we could share a link like this 40 00:01:41,940 --> 00:01:44,140 which has some query parameters. 41 00:01:44,140 --> 00:01:46,770 And if another user uses that link, 42 00:01:46,770 --> 00:01:51,770 the quotes would automatically be sorted as we sorted them. 43 00:01:51,910 --> 00:01:54,530 So that we can save that extra bit of information 44 00:01:54,530 --> 00:01:57,610 on how the quotes should be sorted in ascending 45 00:01:57,610 --> 00:01:59,000 or descending order 46 00:01:59,000 --> 00:02:02,150 that we can save this piece of information in the URL. 47 00:02:02,150 --> 00:02:04,010 And we do sort them accordingly 48 00:02:04,010 --> 00:02:06,600 if someone uses this URL. 49 00:02:06,600 --> 00:02:08,500 And if we use this URL 50 00:02:08,500 --> 00:02:10,169 without the query parameters, 51 00:02:10,169 --> 00:02:12,310 we get the default sorting. 52 00:02:12,310 --> 00:02:14,033 That's what I wanna implement now. 53 00:02:14,960 --> 00:02:18,420 Now for this, I'll start here in this JSX code, 54 00:02:18,420 --> 00:02:19,710 in this fragment. 55 00:02:19,710 --> 00:02:21,210 Here I wanna add a new div 56 00:02:21,210 --> 00:02:24,640 with a class name of classes.sorting. 57 00:02:24,640 --> 00:02:27,790 That's simply one of the predefined CSS classes 58 00:02:27,790 --> 00:02:29,510 you find in that CSS file, 59 00:02:29,510 --> 00:02:32,140 which was part of the starting project. 60 00:02:32,140 --> 00:02:33,220 And in that div, 61 00:02:33,220 --> 00:02:35,440 I just wanna add a button, 62 00:02:35,440 --> 00:02:37,640 which should say Sort. 63 00:02:37,640 --> 00:02:42,300 And then actually it will say Sort Ascending for now, 64 00:02:42,300 --> 00:02:44,510 but later this will be dynamic, 65 00:02:44,510 --> 00:02:48,620 so that if we are currently sorting in ascending order, 66 00:02:48,620 --> 00:02:51,170 this button says Sort Descending 67 00:02:51,170 --> 00:02:52,490 because we would be switching 68 00:02:52,490 --> 00:02:55,000 to sorting in descending order 69 00:02:55,000 --> 00:02:56,170 and vice versa. 70 00:02:56,170 --> 00:02:58,620 But for the moment, I'll hard-code it. 71 00:02:58,620 --> 00:03:00,680 Then we wanna add a click listener 72 00:03:00,680 --> 00:03:04,300 and fire a function when this button is clicked. 73 00:03:04,300 --> 00:03:08,080 For example, the changeSortingHandler function 74 00:03:08,080 --> 00:03:10,033 could be a function we define here. 75 00:03:10,980 --> 00:03:13,750 And then we point that to this function here. 76 00:03:13,750 --> 00:03:16,390 And now the goal here is to change 77 00:03:16,390 --> 00:03:19,350 how we sort our quotes. 78 00:03:19,350 --> 00:03:22,080 Now for this, we could use a state 79 00:03:22,080 --> 00:03:23,560 and then execute some code 80 00:03:23,560 --> 00:03:25,320 that sorts our quotes. 81 00:03:25,320 --> 00:03:27,180 And update this state then 82 00:03:27,180 --> 00:03:29,230 and output our state quotes. 83 00:03:29,230 --> 00:03:31,450 So the sorted quotes down there, 84 00:03:31,450 --> 00:03:33,840 but I'll not do it like this. 85 00:03:33,840 --> 00:03:36,370 Instead I wanna work with query parameters. 86 00:03:36,370 --> 00:03:38,550 And one of the things I wanna do here 87 00:03:38,550 --> 00:03:40,730 in this changeSortingHandler, 88 00:03:40,730 --> 00:03:43,870 is I wanna update the query parameters 89 00:03:43,870 --> 00:03:45,800 in the URL. 90 00:03:45,800 --> 00:03:46,890 So, for the moment, 91 00:03:46,890 --> 00:03:48,330 I'll not sort yet, 92 00:03:48,330 --> 00:03:50,980 but I'll just update the URL 93 00:03:50,980 --> 00:03:54,223 so that we update this shareable URL. 94 00:03:55,220 --> 00:03:56,053 And for this, 95 00:03:56,053 --> 00:04:00,420 we can again import a hook from React Router. 96 00:04:00,420 --> 00:04:03,170 So, from React Router DOM, I'll import a hook. 97 00:04:03,170 --> 00:04:05,420 And the hook I'll import is again 98 00:04:05,420 --> 00:04:07,520 the useHistory hook, 99 00:04:07,520 --> 00:04:09,950 because you'll learnt that this hook allows us 100 00:04:09,950 --> 00:04:12,000 to change the page history. 101 00:04:12,000 --> 00:04:14,690 It allows us to change the URL therefore. 102 00:04:14,690 --> 00:04:16,290 And we can use this hook 103 00:04:16,290 --> 00:04:18,750 and the history object it returns 104 00:04:18,750 --> 00:04:20,430 to add query parameters 105 00:04:20,430 --> 00:04:22,163 to the currently loaded page. 106 00:04:23,360 --> 00:04:26,040 For this, I'll just execute useHistory, 107 00:04:26,040 --> 00:04:28,710 and I'll get this history object. 108 00:04:28,710 --> 00:04:31,260 And now in the changeSortingHandler, 109 00:04:31,260 --> 00:04:35,340 we can call history push. 110 00:04:35,340 --> 00:04:36,570 Push or replace, 111 00:04:36,570 --> 00:04:37,700 and I'll go for a push 112 00:04:37,700 --> 00:04:40,240 so that we could use the back button to go back 113 00:04:40,240 --> 00:04:41,870 to the last sorting, 114 00:04:41,870 --> 00:04:44,880 to the URL before we changed it. 115 00:04:44,880 --> 00:04:49,880 And then here, we can set our new path 116 00:04:50,030 --> 00:04:53,840 and there, I wanna set it to '/quotes' 117 00:04:53,840 --> 00:04:56,510 because that's the page in which we are. 118 00:04:56,510 --> 00:04:58,880 And then I wanna add a query parameter 119 00:04:58,880 --> 00:05:00,360 with a question mark, 120 00:05:00,360 --> 00:05:02,250 and then sort, 121 00:05:02,250 --> 00:05:04,480 and set this equal to some value. 122 00:05:04,480 --> 00:05:06,770 Now this key name is up to you by the way. 123 00:05:06,770 --> 00:05:08,650 It doesn't have to be sort. 124 00:05:08,650 --> 00:05:10,820 but I will use sort as a key 125 00:05:10,820 --> 00:05:13,310 which holds my sorting information. 126 00:05:13,310 --> 00:05:16,490 And then I'll set a dynamic value here, 127 00:05:16,490 --> 00:05:20,860 which I derive on our current state. 128 00:05:20,860 --> 00:05:23,750 So, if we're currently sorting in ascending 129 00:05:23,750 --> 00:05:25,520 or descending order. 130 00:05:25,520 --> 00:05:29,130 And we will later make this truly dynamic. 131 00:05:29,130 --> 00:05:32,860 For the moment, I'll always add ascending here. 132 00:05:32,860 --> 00:05:34,660 And therefore, of course, for the moment, 133 00:05:34,660 --> 00:05:37,680 we could also just use one hard-coded string. 134 00:05:37,680 --> 00:05:39,330 But soon this will be dynamic 135 00:05:39,330 --> 00:05:41,603 and it will not always be ascending. 136 00:05:42,680 --> 00:05:45,340 Now, if we save this code like this, 137 00:05:45,340 --> 00:05:47,490 you will now see this button. 138 00:05:47,490 --> 00:05:50,100 And if I click this button, 139 00:05:50,100 --> 00:05:52,200 you see the URL changes 140 00:05:52,200 --> 00:05:54,630 and this query parameter is added. 141 00:05:54,630 --> 00:05:56,173 Now that's step number one. 142 00:05:57,100 --> 00:05:59,550 Step number two is that we wanna read 143 00:05:59,550 --> 00:06:01,660 that query parameter value 144 00:06:01,660 --> 00:06:03,700 and act accordingly. 145 00:06:03,700 --> 00:06:05,440 And then change the sorting, 146 00:06:05,440 --> 00:06:06,980 change the button label 147 00:06:06,980 --> 00:06:07,823 and so on. 148 00:06:09,670 --> 00:06:11,870 Now, reading query parameter values 149 00:06:11,870 --> 00:06:14,400 is also relatively straightforward, 150 00:06:14,400 --> 00:06:16,290 but we need to use yet another hook 151 00:06:16,290 --> 00:06:18,810 provided by React Router DOM, 152 00:06:18,810 --> 00:06:20,333 the useLocation hook. 153 00:06:21,300 --> 00:06:23,980 Where useHistory gives us access 154 00:06:23,980 --> 00:06:25,680 to the history object, 155 00:06:25,680 --> 00:06:27,870 an object that allows us to change 156 00:06:27,870 --> 00:06:30,330 and manage the URL, 157 00:06:30,330 --> 00:06:33,640 useLocation gives us access to a location object 158 00:06:33,640 --> 00:06:36,780 which has information about the currently loaded page, 159 00:06:36,780 --> 00:06:39,810 about the currently loaded URL. 160 00:06:39,810 --> 00:06:42,340 So here we can call useLocation 161 00:06:42,340 --> 00:06:45,280 and we get such a location object. 162 00:06:45,280 --> 00:06:46,240 And then for the moment, 163 00:06:46,240 --> 00:06:48,770 I'll just log location here 164 00:06:48,770 --> 00:06:50,913 directly in the component function. 165 00:06:51,970 --> 00:06:54,530 With this, if I opened the dev tools, 166 00:06:54,530 --> 00:06:56,940 if I reload, we see this object, 167 00:06:56,940 --> 00:06:59,080 that's our location object. 168 00:06:59,080 --> 00:07:01,500 And here we see a bit of information. 169 00:07:01,500 --> 00:07:03,940 We see the path name, for example, 170 00:07:03,940 --> 00:07:05,660 of the page which was loaded. 171 00:07:05,660 --> 00:07:07,620 And we see this search property, 172 00:07:07,620 --> 00:07:10,480 which holds our query parameter data. 173 00:07:10,480 --> 00:07:12,033 And that's very interesting. 174 00:07:13,400 --> 00:07:16,670 Also interesting is that if I click Sort Ascending, 175 00:07:16,670 --> 00:07:18,410 we see that this location object 176 00:07:18,410 --> 00:07:21,040 gets logged over and over again. 177 00:07:21,040 --> 00:07:24,530 So, that means that pushing this page here 178 00:07:24,530 --> 00:07:26,880 actually rerenders this component. 179 00:07:26,880 --> 00:07:28,360 And that actually makes sense 180 00:07:28,360 --> 00:07:30,310 because when we push a page, 181 00:07:30,310 --> 00:07:32,910 even if it's the page we're currently on, 182 00:07:32,910 --> 00:07:36,600 then this page component is re-evaluated, 183 00:07:36,600 --> 00:07:40,280 because React Router sees that we changed the history 184 00:07:40,280 --> 00:07:42,700 and it therefore rerenders the page 185 00:07:42,700 --> 00:07:44,430 which should be shown to us, 186 00:07:44,430 --> 00:07:47,300 even if it's the page we're currently on. 187 00:07:47,300 --> 00:07:49,130 And that's a useful mechanism 188 00:07:49,130 --> 00:07:51,870 which we will actually use to our advantage 189 00:07:51,870 --> 00:07:53,123 in a couple of minutes. 190 00:07:54,760 --> 00:07:56,070 So, we got this location object 191 00:07:56,070 --> 00:07:58,140 which has this search property 192 00:07:58,140 --> 00:08:00,350 with the query parameter data. 193 00:08:00,350 --> 00:08:01,890 Now we can translate this 194 00:08:01,890 --> 00:08:03,780 into a JavaScript object, 195 00:08:03,780 --> 00:08:06,040 which is a bit easier to use for us 196 00:08:06,040 --> 00:08:08,690 than this plain string here, 197 00:08:08,690 --> 00:08:13,120 by instantiating a new URLSearchParams object. 198 00:08:13,120 --> 00:08:16,330 And that's a built-in constructor function 199 00:08:16,330 --> 00:08:17,840 built into the browser. 200 00:08:17,840 --> 00:08:20,300 So this is not coming from React Router, 201 00:08:20,300 --> 00:08:21,900 not coming from React. 202 00:08:21,900 --> 00:08:25,630 This is a default JavaScript constructor function, 203 00:08:25,630 --> 00:08:28,270 a default JavaScript class so to say, 204 00:08:28,270 --> 00:08:30,083 which we can use in the browser. 205 00:08:31,050 --> 00:08:32,929 Now to this constructor, 206 00:08:32,929 --> 00:08:35,602 we can pass location.search. 207 00:08:36,620 --> 00:08:38,309 So, this string here, 208 00:08:38,309 --> 00:08:39,780 including the question mark, 209 00:08:39,780 --> 00:08:42,370 this is now passed to that constructor. 210 00:08:42,370 --> 00:08:43,830 And that will then give us 211 00:08:43,830 --> 00:08:47,080 a nice queryParams object. 212 00:08:47,080 --> 00:08:49,140 Our object where we can then extract 213 00:08:49,140 --> 00:08:51,750 our query parameters by key. 214 00:08:51,750 --> 00:08:54,300 So here, for example, I have the sort key 215 00:08:54,300 --> 00:08:56,620 with a value of asc 216 00:08:56,620 --> 00:08:59,793 and because I'm using URLSearchParams, 217 00:08:59,793 --> 00:09:04,010 this queryParams object will now have a sort key, 218 00:09:04,010 --> 00:09:07,040 which will hold this asc value. 219 00:09:07,040 --> 00:09:08,560 And that's simply a more convenient way 220 00:09:08,560 --> 00:09:12,150 of extracting data from the query parameters. 221 00:09:12,150 --> 00:09:14,870 So now, we can create a new helper constant, 222 00:09:14,870 --> 00:09:17,667 and we could name it isSortingAscending. 223 00:09:19,990 --> 00:09:22,940 And here we can now use queryParams 224 00:09:22,940 --> 00:09:25,570 and there we can call a get method. 225 00:09:25,570 --> 00:09:27,948 And get one of our queryParams keys, 226 00:09:27,948 --> 00:09:29,814 in this case sort. 227 00:09:29,814 --> 00:09:33,364 Sort, because we have sort as a key here 228 00:09:33,364 --> 00:09:34,947 in our queryParams. 229 00:09:36,538 --> 00:09:38,485 This will then give us the value stored 230 00:09:38,485 --> 00:09:40,035 for that key in the queryParams. 231 00:09:40,035 --> 00:09:43,699 So in this case, A-S-C, asc. 232 00:09:43,699 --> 00:09:45,868 And now we can check if that 233 00:09:45,868 --> 00:09:48,660 is then equal to asc here. 234 00:09:48,660 --> 00:09:49,786 And if that is equal, 235 00:09:49,786 --> 00:09:52,168 we know we are sorting in ascending mode 236 00:09:52,168 --> 00:09:55,040 because the query parameter has a value of asc. 237 00:09:55,040 --> 00:09:58,750 If the query parameter has a value different from asc, 238 00:09:58,750 --> 00:10:00,220 then this will be false 239 00:10:00,220 --> 00:10:03,250 because then we're not sorting in ascending mode. 240 00:10:03,250 --> 00:10:06,400 And now we can use isSortingAscending 241 00:10:06,400 --> 00:10:09,610 to, for example, make this button more dynamic. 242 00:10:09,610 --> 00:10:12,400 It should not always say Sort Ascending, 243 00:10:12,400 --> 00:10:14,730 instead, depending on if we're currently 244 00:10:14,730 --> 00:10:16,850 sorting in ascending mode or not, 245 00:10:16,850 --> 00:10:19,270 it should say Sort Descending 246 00:10:19,270 --> 00:10:21,610 if we are sorting in ascending mode, 247 00:10:21,610 --> 00:10:23,190 because then clicking the button 248 00:10:23,190 --> 00:10:25,700 should switch to descending sorting. 249 00:10:25,700 --> 00:10:28,220 And only if we are currently sorting 250 00:10:28,220 --> 00:10:29,810 in descending order, 251 00:10:29,810 --> 00:10:32,210 clicking the button should switch to ascending order. 252 00:10:32,210 --> 00:10:34,503 So, then it should say Sort Ascending. 253 00:10:36,800 --> 00:10:39,700 And I also wanna make this dynamic now, 254 00:10:39,700 --> 00:10:42,130 how we change our URL. 255 00:10:42,130 --> 00:10:44,210 I don't always wanna set the value 256 00:10:44,210 --> 00:10:45,383 of sort to asc. 257 00:10:46,530 --> 00:10:49,880 Instead here, I wanna check if sort ascending, 258 00:10:49,880 --> 00:10:51,260 if sorting ascending, 259 00:10:51,260 --> 00:10:52,280 if that is true, 260 00:10:52,280 --> 00:10:53,710 which means we're currently sorting 261 00:10:53,710 --> 00:10:55,220 in ascending mode. 262 00:10:55,220 --> 00:10:56,160 And if it is true, 263 00:10:56,160 --> 00:10:58,280 I wanna switch to descending mode. 264 00:10:58,280 --> 00:10:59,550 And only if it's false, 265 00:10:59,550 --> 00:11:02,240 so if we're not yet sorting in ascending mode, 266 00:11:02,240 --> 00:11:03,973 I wanna switch to ascending mode. 267 00:11:05,450 --> 00:11:06,870 And with those changes made, 268 00:11:06,870 --> 00:11:08,580 if we save this, 269 00:11:08,580 --> 00:11:10,970 we see that if I now click this button, 270 00:11:10,970 --> 00:11:12,890 the URL changes 271 00:11:12,890 --> 00:11:15,270 and the button text also changes. 272 00:11:15,270 --> 00:11:17,100 The list does not yet change, 273 00:11:17,100 --> 00:11:20,180 but we are changing the query parameters. 274 00:11:20,180 --> 00:11:21,690 And now we can also use that 275 00:11:21,690 --> 00:11:23,860 to sort the list. 276 00:11:23,860 --> 00:11:27,490 Now, for this attached you find a sorting JS file, 277 00:11:27,490 --> 00:11:30,230 which contains a sortQuotes function. 278 00:11:30,230 --> 00:11:31,970 You can simply add this function 279 00:11:31,970 --> 00:11:34,150 in your QuoteList component file 280 00:11:34,150 --> 00:11:38,310 before you define that QuoteList component function. 281 00:11:38,310 --> 00:11:40,330 So, right after the imports, 282 00:11:40,330 --> 00:11:42,770 before I have my component function, 283 00:11:42,770 --> 00:11:43,893 I insert sortQuotes. 284 00:11:45,280 --> 00:11:47,090 Now that's a little helper function 285 00:11:47,090 --> 00:11:51,210 which will simply sort an array of quotes by ID. 286 00:11:51,210 --> 00:11:54,200 And then depending on whether we're sorting in ascending 287 00:11:54,200 --> 00:11:55,590 or descending order, 288 00:11:55,590 --> 00:11:59,840 the bigger or smaller IDs will be prioritized. 289 00:11:59,840 --> 00:12:02,080 And we can now call sortQuotes 290 00:12:02,080 --> 00:12:04,903 to derive our, well, sorted quotes. 291 00:12:06,280 --> 00:12:08,533 For this here in this component function, 292 00:12:10,260 --> 00:12:14,020 we can get our sortedQuotes by calling sortQuotes 293 00:12:15,180 --> 00:12:17,560 whenever this component rerenders. 294 00:12:17,560 --> 00:12:20,900 And here we then pass in props.quotes. 295 00:12:20,900 --> 00:12:24,000 So, the quotes we get through props. 296 00:12:24,000 --> 00:12:25,500 And as a second argument, 297 00:12:25,500 --> 00:12:27,710 sortQuotes wants to know the order. 298 00:12:27,710 --> 00:12:29,540 It wants to know whether we wanna sort 299 00:12:29,540 --> 00:12:31,120 in ascending or descending order, 300 00:12:31,120 --> 00:12:33,230 and it wants a boolean here. 301 00:12:33,230 --> 00:12:36,697 And here, I'll therefore pass in isSortingAscending. 302 00:12:38,010 --> 00:12:40,940 And then sortedQuotes can be used 303 00:12:40,940 --> 00:12:44,230 to actually output the quote items. 304 00:12:44,230 --> 00:12:46,230 So, here I'll use sortedQuotes 305 00:12:46,230 --> 00:12:48,710 instead of prop quotes. 306 00:12:48,710 --> 00:12:51,540 And since this component function will be re-executed 307 00:12:51,540 --> 00:12:54,410 whenever we change the query parameters, 308 00:12:54,410 --> 00:12:56,440 we will get new sorted quotes 309 00:12:56,440 --> 00:12:59,130 whenever the query parameters change. 310 00:12:59,130 --> 00:13:01,430 So with this, now, if I reload, 311 00:13:01,430 --> 00:13:02,930 if I click Sort Descending, 312 00:13:02,930 --> 00:13:07,930 you see the order of my list items also changes. 313 00:13:12,300 --> 00:13:14,120 So now, here we can sort, 314 00:13:14,120 --> 00:13:17,150 and now we got this reusable URL. 315 00:13:17,150 --> 00:13:18,750 And if I grab that URL, 316 00:13:18,750 --> 00:13:20,560 for example in descending mode, 317 00:13:20,560 --> 00:13:22,350 and I share it with someone, 318 00:13:22,350 --> 00:13:25,890 that person also starts in descending mode. 319 00:13:25,890 --> 00:13:27,530 If I grab the URL 320 00:13:27,530 --> 00:13:29,370 and share it in ascending mode, 321 00:13:29,370 --> 00:13:32,530 that person also starts in ascending mode. 322 00:13:32,530 --> 00:13:35,690 So, that's an example for using query parameters. 323 00:13:35,690 --> 00:13:37,470 And that's how we can work with them 324 00:13:37,470 --> 00:13:39,093 with React Router. 23525

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.