How to use the useReducer Hook - Better than useState for managing objects, arrays or complex data

preview_player
Показать описание
React JS Tutorial - useReducer

You probably use the useState hook in every app, but did you know that in many cases the useReducer hook is even better!

Whether you're storing arrays, objects or just have conditions to apply to your state, the useReducer hook take a function as its first argument to allow you to play with the data before storing to the state.

Once you learn useReducer, you'll find yourself using it again and again.

00:00 - Introduction
00:30 - useState example
01:22 - converting to useReducer
03:35 - Setting a reducer function
05:10 - useReducer to condition data
07:35 - Switch Case to set the state data
08:47 - Summary

#ReactJS #reactuseReducer #useReducer
Рекомендации по теме
Комментарии
Автор

Nice explanation, could you make a video on an Array too just like you use an object as initialState or any GitHub repo for reference.

munavarsheik
Автор

Can we give reducerFunctionName directly like below instead of () => dispatch({type: 'RESET'})
<button onClick={() =>

munavarsheik
Автор

Hi sir, Iam a student . This can be done using useState too.i dont know which way is best but i have seen people useState to work with form by giving useState a value object with name and password

shankhan
join shbcf.ru