Hope you enjoyed the video! I also have a really cool and unique course that will teach you way more than this video. You'll learn how to build an actual complex project with React. It's called "Project React" and you can find it at cosden.solutions/project-react. Also, I have a free weekly newsletter called "Import React" with tutorials, news, and cool stuff about React! You can sign up at cosden.solutions/newsletter?s=ytc
Hi Cosden, I have been working with Angular for years and now I'm learning React to enrich my skillset as a front end developer. Your videos is always concise and easy to understand that help me to save a lot of time. Thank you so much.
Enjoying your channel. Subscribed. I have seen a few times people mention (usually using this counter example) that was should do something like `setCount(prevState => prevstate + 1)` I can't remember the reasoning for this but it had something to do with the state properly updating? Do you know what I am talking about and could you disucss that? Is it needed? Why do we do this instead of just `setCount(count + 1)`?
Doing it that way is a way to guarantee you're getting the most up to date state, which sometimes is harder to get because of how React renders work. Search examples for this online and you'll see why
really appreciate the small videos explaining big concepts so well but i think you should have talked about the asynchronous nature of useState here. in real world applications, more often than not ive gotten stumped by this async nature where the state just wont update! would really appreciate a video on that, if possible!
the setState is tricky, cause if you do like that (setCount(count + 1) ) and when there is another async process that change the state, the value will not valid.. you should use this approach setCount(recentCount => recentCount + 1 ) it will using recent value and calculate it.
Yes, this is correct. It's nice that this video present this as simply as possible, but doing things the way it's presenting is going to set devs up for future confusion and problems.
Nice video but I was expecting that you could explain more about the difference between using function to set a state ex. instead of setCount(count + 1) others are using setCount(prevState => prevState + 1)
cause setState function is async process, so the React do not guarantee that if you use this approach (setCount(count + 1)) it will always correct, so react give you saver approach (setCount(callback)) to make sure your function to set the state will be always correct.
Thanks for the video and for the taking the time to explain how useState works. It is so damn simple. Now, I am going to teach this to my mentees. They won't know that this is me as I am not using my real name,. hahaha! Thanks a lot!
ok, yes that's a simple example, but should to mention about "prev" because an App going to be crashed once when we change many useStates in the same time.
Sir can you instead show us how to use useState in manipulating DOM elements or classes. That would be more helpful to us beginners who is more into designing our react apps as an aspiring frontend dev.. just suggesting thankyou for your videos ❤️
I suggest editing this video and adding an important concept. For example, why do you need the hook in the first place? I mean why don't you just use a JS variable instead? setState causes the whole component to be re-rendered. You cannot fully understand without fully understanding the component lifecycle.
Thank you. Why wouldn’t you just set a variable count and have a function that adds 1 and have the button call the function? I’m new to react and use state.
because in React components, doing it that way wouldn't cause a re-render and your new value wouldn't show on the screen! You need state to trigger an update and then it will show!
you should always use state for things that you want to track and update over time. The only use case for using something like a variable without state is when you want to derive something from state. But everything should be driven from state in React
understood but what happens when i use normal variables instead of State variables? I can use them seamlessly. While using state variables I face difficulty as they require a queue to call set functions. that is not the case with normal variables.
I love your videos, but i actually disliked this one. It wasn't like your other videos. Watching all those amazing video that covers every corners and addresses all edges cases made an expectation. But nuh, this wasn't one of those. Hope your create another video and address those as well. By the way thank you.
Hope you enjoyed the video! I also have a really cool and unique course that will teach you way more than this video. You'll learn how to build an actual complex project with React. It's called "Project React" and you can find it at cosden.solutions/project-react. Also, I have a free weekly newsletter called "Import React" with tutorials, news, and cool stuff about React! You can sign up at cosden.solutions/newsletter?s=ytc
You explained nothinng
const [count, setCount] = useState(0);
still does not make any sense at all.
Hi Cosden, I have been working with Angular for years and now I'm learning React to enrich my skillset as a front end developer.
Your videos is always concise and easy to understand that help me to save a lot of time.
Thank you so much.
The way you teach react tells how experienced you are
Keep uploading videos
Simple, quick, and efficient, thank you!
bro, this is seriously the best explanation on youtube. Please keep them coming!
finally !! after watching 1000s of videos, a dude that explains! clearly how the hooks work, thank you ! 🙏💪
so because of useState(), I can click the 'Like' button on this video and the like counter can increment? 😆
Hahahaha yes exactly ☺️
Then click on it again to test the decrement :))
Lol j4f don't do that haha
I like the way you explain things that other videos do not explain, such is the naming conventions! Great work. Subscribed!
You simplified the complexity of this concept! Thanks so much!
You are the best teacher! Thank you for you real help and your tami and work!!!
Oh my.. you explain it so well!
Really, this was my last tutorial for using the state hook. Thanks for your effort.💗
thank you for sharing, greetings from Brazil!
You are an amazing teacher! Thank you!
Thank You so much! your channel is underrated!
Daaaaamn you are a god or what, i wasted my 5 hours on this and you taught me in 10 minutes, salute man
Enjoying your channel. Subscribed. I have seen a few times people mention (usually using this counter example) that was should do something like `setCount(prevState => prevstate + 1)`
I can't remember the reasoning for this but it had something to do with the state properly updating? Do you know what I am talking about and could you disucss that? Is it needed? Why do we do this instead of just `setCount(count + 1)`?
Doing it that way is a way to guarantee you're getting the most up to date state, which sometimes is harder to get because of how React renders work. Search examples for this online and you'll see why
Awesome!!! please do more of those on other React subjects🙏
Yep 🤙
Simple and detail Thanks For The Effort 🙌
Lovely job, bro! Subscribed and liked. Please cover each hook individually and create a list, it would be awesome. Thanks a lot! 😍👍
There's a playlist already ☺️ but yes planning to do all of them
Very simplified explanation!
Thanks!
Subbed, your videos and explanations are fantastic! Thank you!
really appreciate the small videos explaining big concepts so well but i think you should have talked about the asynchronous nature of useState here. in real world applications, more often than not ive gotten stumped by this async nature where the state just wont update! would really appreciate a video on that, if possible!
fair enough, this was my first ever video though 😅
the setState is tricky, cause if you do like that (setCount(count + 1) ) and when there is another async process that change the state, the value will not valid.. you should use this approach setCount(recentCount => recentCount + 1 ) it will using recent value and calculate it.
so if there is any recent value involve, please make sure using this approach (using callback), rather than directly inject state
Yes, this is correct. It's nice that this video present this as simply as possible, but doing things the way it's presenting is going to set devs up for future confusion and problems.
I was actually surprise he just use (count + 1) instead of update the count with recentCount instead
best tutorial i have se in a while
You are a saviour my friend 🙏
i swear you're a life saver
I love the explanation bro
Thanks a lot
Keep up the good work
Thanks for clear and to the target explanation...
Thank you for this. I understand the useState now hahaha😆😆
Thank You, you are a good teacher.
Much appreciated, best tutorial out on this
Just subbed cause I like the way you describe things good job
Nice video but I was expecting that you could explain more about the difference between using function to set a state ex. instead of setCount(count + 1) others are using setCount(prevState => prevState + 1)
cause setState function is async process, so the React do not guarantee that if you use this approach (setCount(count + 1)) it will always correct, so react give you saver approach (setCount(callback)) to make sure your function to set the state will be always correct.
Thanks for the video and for the taking the time to explain how useState works. It is so damn simple. Now, I am going to teach this to my mentees. They won't know that this is me as I am not using my real name,. hahaha! Thanks a lot!
made it make too much sense, i think imma watch ur playlist now
Greetings Good luck! From Sri lanka❤
thank you! love sri lanka :D colombo is a great city
just WOW! this was really helpful! thanks! new sub here
I loved this video keep up the good work
I guess you were right; I do have a better understanding of useStates now. What gets me is the word interface you used.
Nice one!... Liked it!
ok, yes that's a simple example, but should to mention about "prev" because an App going to be crashed once when we change many useStates in the same time.
by the way, what is your opinion on AI, copilot for example, Is it worth it to keep learning how to code?
Sir can you instead show us how to use useState in manipulating DOM elements or classes. That would be more helpful to us beginners who is more into designing our react apps as an aspiring frontend dev.. just suggesting thankyou for your videos ❤️
this dude is awesome
Great tutorial brother
Solid tutorial. New subscriber here!
Thank you!
Thank you soo much this is so much better
😍
glad you found it useful!
Great.
How to handle multiple or object and array in useState?
great thank you!
Fantastic!😉
well explained!!
Man I feel like Luka Doncic is teaching 😂
I like your video but you did not mention about preVal in state. I think this is so important that you can not avoid to mention
thank uuu
hi, thanks... You are awesome... Make more videos
Will do!
do you have tutorial that all hook can be use?
can u also make a video on how react re-renders when usestate state is changed and how does useState use object.is() under the hood
That's a bit of an advanced topic 😅 I'm still doing beginner videos so it'll take some time!
but you didn't say how the rest of the program gets access to the count value. should the count functions broadcast messages when count has changed?
thank u
I suggest editing this video and adding an important concept.
For example, why do you need the hook in the first place? I mean why don't you just use a JS variable instead?
setState causes the whole component to be re-rendered.
You cannot fully understand without fully understanding the component lifecycle.
Nice
what's the different between using a state and using a normal variable and reassigning it ?
State triggers a re-render of the component so you can see the new value in the UI, variable assigning will not work consistently in React
Thank you. Why wouldn’t you just set a variable count and have a function that adds 1 and have the button call the function? I’m new to react and use state.
because in React components, doing it that way wouldn't cause a re-render and your new value wouldn't show on the screen! You need state to trigger an update and then it will show!
thank Youuu
Can you please make one video where we get to know difference between using useState hook instead of normal variables using let keyword
you should always use state for things that you want to track and update over time. The only use case for using something like a variable without state is when you want to derive something from state. But everything should be driven from state in React
understood but what happens when i use normal variables instead of State variables? I can use them seamlessly. While using state variables I face difficulty as they require a queue to call set functions. that is not the case with normal variables.
I love your videos, but i actually disliked this one.
It wasn't like your other videos.
Watching all those amazing video that covers every corners and addresses all edges cases made an expectation.
But nuh, this wasn't one of those.
Hope your create another video and address those as well.
By the way thank you.
This is my first ever video my dude ☺️
He didn't introduce the
setState(prev => prev+1)
syntax
zoom in your code screen
hello
whole lotta capping in the intro, the video is clear but thats not everything about useState().
Hello sir i have double. Why can't we use count++ instead of count + 1 ????
admin, i heve best offer for you . How can we talk
Discord