1. Thanks for preemptively answering useState vs useReducer, a lot of guides leave these questions unanswered which causes indecision for people dealing with more architectural problems. 2. Good call on use-immer, didn't know that was a thing, and state.map was running rampant in my cases
@pjguitar153 жыл бұрын
You made it the simplest possible. this is the third video I watch about useReducer, and finally I understand it!
@georgegeorgio702 жыл бұрын
5:08 what is the difference between state++ and state + 1? Why the first one is "mutating" the state and the other one isn't? They both add one just the ++ syntax console.logs the incremented value on "the next line", where as the + 1 syntax console.logs the value updated "on the same line"(if that makes any sense). Im new to js and react, could somebody please clarify? Thx :)
@MassHypnosis8052 жыл бұрын
This was exactly what I needed thank you so much. I had an array in an object that I had to change but just couldn't get it right. I was even passing in the index but didn't know how to use it in the reducer function. I spent a lot of time trying to figure out how to update my array. This cleared everything up, in a easy to understand manner. Thank you! I did run into an issue because I had other items in the reducer state besides the array so if anyone is wondering how to use it with many different objects you can change the return statement of 'toggle-todo' to this: return ( {...state, todos: state.todos.map((t, i) => idx === action.idx ? { ...t, completed: !t.completed } : t)} ); This way you can update just the array. A use case for useReducer is to have one state with many different types of objects. So you can easily have the 'text' state in this example as part of a single useReducer as long as you return ...state and the map function.
@haciendadad4 жыл бұрын
Great video! I was watching a PluralSight course on Hooks and he never really explained the useReducer, he was using but I couldn't get what the params were referring to, finally I had to come to YT and found this video. In 5 mins, I had my answer and was clear now, plus I learned w whole lot more! I subscribing and coming back here to absorb as much as possible. After looking at Ben's list of videos, man, I feel like I died and went to Coder Heaven! Looking at all the videos, I don't know where to go next? Actually, Next.js is where I want to go next! I think Ben really gets it, so I am staying here, no more course sites. I am between jobs, but when I get one, I'll become a Patreon! Thanks Ben!
@jordanlam81773 жыл бұрын
great teacher! not over complicating anything and straight to the point
@michaellanning1084 жыл бұрын
Great tutorial, thank you. I’m finally starting to grasp this.
@alexandershpilka58484 жыл бұрын
What's missing is an example of async logic combined with useReducer. Still a great tutorial. Thank you.
@nsgirish4 жыл бұрын
Thanks for the excellent explanation and that smooth coding style
@nicotomomate4 жыл бұрын
12:50 I felt you was really enjoying clicking those toggles 😂
@rohandevaki43494 жыл бұрын
at 5:25, why didnt u use state++, please explain in depth, i didnt understand what were you talking about mutating the state, and returning a new state.
@shubhamh74513 жыл бұрын
same! I researched about it to check whether they make duplicate copies or change the same, but I didn't get any, did you find anything?
@philippalbrecht90234 жыл бұрын
Love your teaching style, great pace 👌
@ahmedroberts48832 жыл бұрын
Very clean! You have just helped me tremendously. That was super easy to follow. I have been having conceptual blockers with useReducer up until right now. Much appreciated! You definitely have me as a subscriber.
@timothyn46994 жыл бұрын
Very interesting! The way you explain it makes a lot of sense. Thanks for explaining the ...props
@vado40034 жыл бұрын
VIM inside VSCode, I see you're a man of culture as well
@Pareshbpatel3 жыл бұрын
An excellent introduction to useReducer. Thanks. {2021-11-20}
@mikevaleriano95575 жыл бұрын
Man, I can really appreciate how this hook is setup and how people can benefit from this whole new way of doing things in React. But when it comes to state, ever since I started using easy-peasy (it's still Redux, but the whole BS is hidden) I don't even trip about it anymore: Still cool to see the React team thought of everything, but this is one abstraction that easy-peasy made obsolete for me.
@rohanjain42384 жыл бұрын
Ben Awaf 14:46 line 15 you have to decrease the value of toDoCount when the toDo is toggled
@JeafGilbert4 жыл бұрын
So basically if we toggle one item, does it re-render all the todo list items? If we have tons of items, how to re-render only the single clicked item?
@bawad4 жыл бұрын
kzbin.info/www/bejne/pV7EnYWYoMSthpI
@carefree_ladka2 жыл бұрын
What font-family does Ben use in VSCODE?
@sitter22073 жыл бұрын
2:26 why not { dispatch } to call the function when button is clicked, instead of calling it inside a function like you did: { ( ) => dispatch( ) } ?
@xenopheliac72024 жыл бұрын
Very nice video. Might want to note the testability of the pure function over useState.
@chrisy.7033 жыл бұрын
what's the syntax for {type: "add-todo", text } -> is it a object or something mixed?
@funfactor22903 жыл бұрын
Nice tutorial, thanks! Where can I ask for advise if I get stuck and I think it's fairly simple..
@dipinbhattarai53042 жыл бұрын
Damn you type fast Ben!
@MsElsospechoso283 жыл бұрын
such a clean explaination
@LiborPilny2 жыл бұрын
Thanks Ben, even though it is an older one - still nice and useful - and in easy and straight way ;-) 👍
@haythamkenway15613 жыл бұрын
Hi Ben , can we remove text and setText useState and implement it into the reducer?
@marcinb78843 жыл бұрын
the best teacher ever !!!!!!!!
@cappsulecorp4 жыл бұрын
Excellent tutorial, thanks a lot!
@Mydad-et1el4 жыл бұрын
Very good video. Thank you Ben!
@maxandriani4 жыл бұрын
Thankx for the tutorial. I'm looking a way to use useReducer for async tasks like create/remote resorces from api. Can i use this hook?
@dreamyrhodes4 жыл бұрын
Why is it called reducer? That name doesn't make any sense to me.
I don't understand one thing, why did you created separated property for todo count, can't we do state.todos.length ???
@bawad5 жыл бұрын
Yeah it was just demonstrating the concept
@harbilito49104 жыл бұрын
how to use usereducer if i have an api to store initial state of usereducer?
@krishind995 жыл бұрын
In the first example of counter, how's counter automatically passed as STATE parameter in reducer function?
@bawad5 жыл бұрын
that's something useReducer does underneath the hood
@ibealgoody85243 жыл бұрын
Why does every tutorial create the useReducer function in App? Why not in a different file? Is this really best practice?
@MananGouhari4 жыл бұрын
super insightful tutorial!
@chinonsoviktor77774 жыл бұрын
I swear...u made it look so easy.
@zlackbiro4 жыл бұрын
Somebody struggle with the CSS... 😂
@expeng58614 жыл бұрын
why my reducer has been call 2 times.
@youneshenni54173 жыл бұрын
use immer now comes out of the box with Redux Toolkit.
@eddiegomez41345 жыл бұрын
very helpful! Thanks so much!
@Cmxmxmmx74 жыл бұрын
useReducer(reducer,{todos: [ ]}); right part {todos: [ ]} it this mean array todos inside of an object? or it is just array stored in a variable name todos? can we just write useReducer(reducer,: [ ]); const initialState = { backgroundColor: "orange", circlesArray:[1,2,3,4]} if I have initialState like this. How do I add and remove inside the array using switch statement?
@bawad4 жыл бұрын
1. yes 2. if you just want an array then yes 3. [...state, item] state.filter()
@21agdmnm4 жыл бұрын
where did that completed:false came from and why do we need it ??
@bawad4 жыл бұрын
new todos that get added should not be complete to begin with so we do completed:false
@alexanderkim72414 жыл бұрын
What about 3rd parameter of useReducer hook? Do you use it?
@bawad4 жыл бұрын
rarely
@MandosaWright3 жыл бұрын
So in a reducer state + 1 Doesn't mutate state? This is madness! :)
@kmylodarkstar22533 жыл бұрын
[state, action] = [getter, setter]?
@MrPogi-lf5gz5 жыл бұрын
hey Ben. How do you type so fast? How do you navigate so quickly?Can you do a tutorial on that too?
@bawad5 жыл бұрын
vim
@phoenixultimate82534 жыл бұрын
@@bawad How to get good at vim kind sir.
@ThatGuyAnonymous5 жыл бұрын
Great video. Can this technique scale for medium/large scale applications? I have been using redux for some time and this method seems like a less painful way of doing so but I feel like there is a catch I might be missing. your thoughts?
@bawad5 жыл бұрын
yes, just make sure to keep your state local whenever possible
@duchoangbui90684 жыл бұрын
can someone please help me with this? I got this message when I tried to run the code above: Warning: A component is changing an uncontrolled input of type undefined to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component
@geared_rider4 жыл бұрын
Recheck your values in this case. Something is undefined and you are changing the state value of an input component to undefined
@raylom82305 жыл бұрын
Very helpful!
@chrisgiroux93564 жыл бұрын
Could someone please explain me to where the type is getting defined in action.type? Is that something that useReducer is doing?
@bawad4 жыл бұрын
what you pass into dispatch will become the action
@chrisgiroux93564 жыл бұрын
Ben Awad Awesome thanks Ben. Starting redux in my bootcamp next week and been binging on all your videos. You’re an awesome teacher 😎
@Joseph-qb1es4 жыл бұрын
Thanks friend.
@robertosoriano96175 жыл бұрын
Please make an (advanced) Easy Peasy video! where you go over "listening for other actions". Thank you for these tuts!!!
@bawad5 жыл бұрын
I will once I do that with easy peasy
@javierh2k5 жыл бұрын
Thanks Ben. But, is not better to use objects literal to use the switch
@bawad5 жыл бұрын
probably
@tuRistst4 жыл бұрын
Hi. Thx for tutorials, but 11:30 my brain is crushed
@albert219944 жыл бұрын
bloody awesome
@Romanticoneable4 жыл бұрын
Awesome video, thank you very much! I would like to know how do you delete a selected item on the reducer function. Like in your example if I want to delete the 2nd text item, how should I do it? function reducer { ... case "delete-item": return { todos: state.todos.map((t, idx) => idx === action.idx ? {...t, completed: !c.completed(
@CTFlink3 жыл бұрын
you know he's a good programmer when he's using his keyboard to navigate the code more than the mouse 😂
@leoMC43842 жыл бұрын
Good programmer?? There's only 30 lines of code, Einstein.
I've watched like 10 videos on useReducer and I still can't understand it. So much functions, objects, states inside the scope, outside the scope. I feel miserable
@amirchahine16835 жыл бұрын
i have a question i already start react native course in udemy and even 47% alot of things i can understand so i neeed material or other to help me to built app
@bawad5 жыл бұрын
What do you mean?
@steve47182 жыл бұрын
12:20 .. or just look google..
@veer14724 жыл бұрын
He types faster than I think afaik
@jhjhj21723 жыл бұрын
4:37
@finsflexin2 жыл бұрын
If you want to learn it, here’s a better and more updated tutorial by uidotdev m.kzbin.info/www/bejne/jobbgoawpcx0q6s
@fitimzenuni50364 жыл бұрын
#forthealgo
@martinp78412 жыл бұрын
Literally every video uses the same exact example in the docs.
@hirengajjar27862 жыл бұрын
same content , Counter !!!!! it seems all trainer are copying each other content.
@karma_yogi_424 жыл бұрын
why would you use a stupid concept like the immer library?? that would cause a lot of problems if people get into the habit of writing mutable code in react, why not just be a normal developer and write some proper code. >: -[
@mardikagop93464 жыл бұрын
your keyboord voice is very very very annoying, please dont type so fast , you dont need to show as how fast you can type, this is a lesson not a tournament.
@cosmin44374 жыл бұрын
instead of thanking him for making this tutorial, you are complaining about "keyboord voice". P A T H E T I C