All language subtitles for 012 useReducer vs useState for State Management_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
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

Original subtitles

So, now, that we learned about useReducer

let me, again, sum up when you should use useState

and when it might be an idea to use useReducer.

Now, generally, you will know when you need useReducer.

That might not be the greatest rule of all times,

but you will see when you need useReducer,

for example, because using useState becomes too cumbersome,

you find yourself dealing with a lot of kind

of related state snapshots, which still are kind

of independent and you start updating them together

in a way that just doesn't work out.

Then, you want to consider using useReducer.

Now, to still give you a couple of ideas

when to use useState versus useReducer,

useState is your main state management tool.

Typically, you start with useState

and often it's all you need.

It's great for independent pieces of state and data.

It's great for simple state, you could say.

It's great if state updates are easy

and limited to a few kinds of updates.

So, if you don't have a lot of different cases

that will change a state and especially if you don't have,

let's say, an object as a state or anything like that.

Now, if you do have an object as a state

or a more complex state useReducer might be interesting

because, in general, useReducer is great

if you need more power and with more power,

I simply mean that you can write such a reducer function

that can contain more complex state updating logic

where you always are guaranteed to work

with the latest state snapshot.

And where you can move that potentially more complex logic

out of your component function body

into a separate reducer function.

So, all the restructure code, that might be interesting.

You should especially consider useReducer,

if you're dealing with related data

with state that is made up of related pieces of state.

So when you, for example, have a scenario,

as we had it with our form input state.

And, in general, useReducer can be helpful

if you have more complex state updates,

if you have different cases, different actions

that can change a state, cases like this.

Now, there is no hard rule and there, as always

in programming, is no clear wrong or right.

You can certainly also handle cases

where useReducer would be good with just useState,

especially when combining that with useEffect.

But sometimes using useReducer just might

be more elegant, or simpler.

On the other hand, you should absolutely

not always useReducer because often that will be overkill.

If you have just a simple state that just switches

between two different values for example,

using useReducer might be overkill.

And that's it for useReducer.

Now, you could absolutely also use useReducer

to manage the form state as a whole with useReducer,

instead of using useState for the form validity

you could replace these two reducers

and the form validity with one big reducer

that manages the entire form,

but that's something I will come back

to later in the forms module.

Since, for now, it's just important

that you understand useReducer and when to use it.

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